I created an app that required a user to snap a photo and save it to the MySQL database. There are 3 buttons it that activity which is "Camera", "Save", and "Next". Currently, if there's no photo at ImageView, user can still go to the next activity if they click "Next" button.
Now, how I want to make sure that the user cannot go to the next activity if there's no image in ImageView. Below is my code:
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(taskClass.getPhoto_before() != null){
Intent intent = new Intent(TaskUpdateBefore.this, TaskUpdateAfter.class);
intent.putExtra("task", taskClass);
startActivity(intent);
}else{
Toast toast = Toast.makeText(TaskUpdateBefore.this,"Please snap a photo and save", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.getView().setBackgroundColor(Color.TRANSPARENT);
TextView alert = toast.getView().findViewById(android.R.id.message);
alert.setTextColor(Color.rgb(213, 56, 23));
alert.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 25);
alert.setTypeface(null, Typeface.BOLD);
alert.setGravity(Gravity.CENTER);
toast.show();
}
}
});
Can anyone knows what is the problem?
If you've not set any image by default the you can check something like
if(imageView.getDrawable!=null){
Intent intent = new Intent(TaskUpdateBefore.this, TaskUpdateAfter.class);
intent.putExtra("task", taskClass);
startActivity(intent);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.