[英]Java Android - tag pictrues from camera roll to add to quiz
I am creating a user generated quiz app.我正在创建一个用户生成的测验应用程序。 The user should be able to select pictures from their camera roll which they can label and add them to a quiz of their choice.For example there will be a quiz called guess the family member where the pictures that the user has uploaded will be used.用户应该能够从他们的相机胶卷中获取 select 张照片,他们可以 label 并将它们添加到他们选择的测验中。例如,将有一个名为猜测家庭成员的测验,其中将使用用户上传的照片。
so far I have been able to allow the user to select a picture from their camera roll and display it on screen however I am unsure how I could label the picures and add them to a specific quiz.到目前为止,我已经能够允许用户 select 从他们的相机胶卷中获取一张照片并将其显示在屏幕上,但是我不确定如何 label 图片并将它们添加到特定的测验中。
would appreciate if anyone could help or give me some guidance.如果有人可以帮助或给我一些指导,我将不胜感激。
public class Editquizz extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editquizz);
FloatingActionButton button = findViewById(R.id.Uploadbtn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 3);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && data != null ){
Uri selectedImage = data.getData();
ImageView imageView = findViewById(R.id.imageView3);
imageView.setImageURI(selectedImage);
}
}
public void onClickHandler12(View view){
Intent myIntenet = new Intent(Editquizz.this,MainActivity.class);
startActivity(myIntenet);
}
You can add an EditText
to your layout and use that to label the image.您可以将EditText
添加到您的布局并将其用于 label 图像。 That does depend on how you are storing the quiz, but adding a string for the label should be simple.这确实取决于您存储测验的方式,但是为 label 添加一个字符串应该很简单。
Quiz:测验:
String url/uri = "https://...";
String label = editText.getText().toString();
One way to store the quiz could be with SharedPreferences
存储测验的一种方法是使用SharedPreferences
SharedPreferences prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE);
prefs.edit().putString("quiz1", url + ";" + label).apply();
and just retrieve it with然后用
String quiz1 = prefs.getString("quiz1", "");
if (!quiz1.isEmpty()) {
String[] split = quiz1.split(";");
String url = "";
String name = "";
if (split.length >= 1) {
url = split[0];
}
if (split.length >= 2) {
name = split[1];
}
}
Or you can save it using sqlite或者您可以使用 sqlite 保存它
Room:房间:
https://developer.android.com/training/data-storage/room https://developer.android.com/training/data-storage/room
GreenDAO:绿道:
https://greenrobot.org/greendao/ https://greenrobot.org/greendao/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.