About dialog with scrollable text and webpage button


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //In for instance onOptionsItemSelected event call
  2. showDialog(MY_ABOUT_DLG_CONSTANT);
  3.  
  4.  
  5. //Then override the onCreateDialog event, and check for
  6. //the int constant that you passed in showDialog.
  7. @Override
  8. protected Dialog onCreateDialog(int id) {
  9. switch (id) {
  10. case MY_ABOUT_DLG_CONSTANT: {
  11. /*
  12. Use the alert dialog builder to create the dialog, and add the string constants "R.string.aboutXXX" in
  13. "strings.xml". Then also add a dialog.xml layout.
  14. */
  15. AlertDialog.Builder d = new AlertDialog.Builder(this);
  16. d.setTitle(R.string.aboutTitle);
  17. d.setIcon(android.R.drawable.ic_menu_info_details);
  18. d.setPositiveButton(R.string.aboutHomepage, new OnClickListener() {
  19. public void onClick(DialogInterface dialog, int which) {
  20. Uri uri = Uri.parse(getString(R.string.aboutHomepageUrl));
  21. startActivity(new Intent(Intent.ACTION_VIEW, uri));
  22. }
  23. });
  24.  
  25. //Just add additional buttons like the button above but add them
  26. //using d.setNeutralButton instead of positive button.
  27.  
  28. d.setNegativeButton(R.string.aboutClose, null);
  29. View v = LayoutInflater.from(this).inflate(R.layout.dialog, null);
  30. TextView text = (TextView) v.findViewById(R.id.dialogText);
  31. text.setText(getString(R.string.aboutText, getVersion()));
  32. d.setView(v);
  33. return d.create();
  34. }
  35. }
  36. }
  37.  
  38. /******************
  39. dialog.xml layout
  40. ********************
  41.  
  42.  
  43. <?xml version="1.0" encoding="utf-8"?>
  44. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  45. android:layout_width="fill_parent" android:layout_height="fill_parent"
  46. android:padding="6dip">
  47. <TextView android:id="@+id/dialogText" android:layout_width="fill_parent"
  48. android:layout_height="wrap_content" android:textSize="12sp"
  49. android:text="Example text." />
  50. </ScrollView>
  51.  
  52. *******************/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.