yoyocx

Dialog

Oct 17th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class PreferenceUtils {
  2.  
  3. private PreferenceUtils(){}
  4.  
  5. public static int setResources (String string, String string2, Context context){
  6. return context.getResources().getIdentifier(string, string2, context.getPackageName());
  7. }
  8.  
  9. public static void dialogOption(final Activity activity){
  10. Context context = activity;
  11. if (!Boolean.valueOf((boolean) PreferenceManager.getDefaultSharedPreferences(context).getBoolean("disable_dialog_key", false)).booleanValue()) {
  12. return;
  13. }else{
  14. tampilkanDialog(activity);
  15. }
  16. }
  17.  
  18. public static void tampilkanDialog(final Activity activity){
  19.  
  20. final AlertDialog.Builder adb = new AlertDialog.Builder(activity);
  21. LayoutInflater adbInflater = LayoutInflater.from(activity);
  22. View view = adbInflater.inflate(setResources("dialog_about", "layout", activity), null);
  23. adb.setView(view);
  24. adb.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
  25. @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
  26. public void onClick(DialogInterface dialog, int which) {
  27. return;
  28. }
  29. });
  30. adb.show();
  31.  
  32. }
  33. }
  34.  
  35. ==== Letakan di activity dimana mau ditampilkan dialog
  36. PreferenceUtils.dialogOption(this);
  37.  
  38. contoh :
  39. public class MainActivity extends AppCompatActivity {
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.activity_main);
  45. PreferenceUtils.dialogOption(this);
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment