Sunday 12 May 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...