Sunday, May 12, 2019

android - How to implement a confirmation (yes/no) DialogPreference?



How can I implement a Preference that displays a simple yes/no confirmation dialog?



For an example, see Browser->Setting->Clear Cache.



Answer



That is a simple alert dialog, Federico gave you a site where you can look things up.



Here is a short example of how an alert dialog can be built.



new AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("Do you really want to whatever?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {


public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(MainActivity.this, "Yaay", Toast.LENGTH_SHORT).show();
}})
.setNegativeButton(android.R.string.no, null).show();

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...