Visitors Today: 53
Total Visits: 422971

www.codester.info

Do you have source code, articles, and tutorials to share?
Visual Basic, VB.NET, C#, PHP/MySQL, C/C++, Java/JavaScript, ASP/ASP.NET, MS Access, FoxPro, SQL
You can write your own content here.

Donation


    If the information on this site helps you and you would like to make donation to XtremeXtension.com please click the LINK below.

    If you want to support us, please make a contribution. Any amount is appreciated. To make a donation via PayPal, credit card, or e-check..

    Please click the DONATE link..

    Your contribution will make XtremeXtension.com grow in the future.

Sponsor

Calendar

Don`t ask me again - popup dialog in an android app

    Posted Anonymous Posted On January 16

    Android Applications 2 Current Comments 1739 Views

    Like 3 people liked this.

      This post takes you through as to on how to include a "don't ask me again" popup dialog in your android app.I have successfully put this in my app. So you may ask any doubts you may have via the comments section below.



    Logic: It sets a value in Android Preferences and checks it to determine whether it will show the dialog or not.





      Create checkbox.xml in resources/layoutsand paste the following:


    SOURCE
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/layout_root"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation="horizontal"
       android:padding="10dp" >
       <CheckBox
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@+id/skip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Ok please do not show again." >
       </CheckBox>
    </LinearLayout>



      Paste the following where you want the box to appear:



    SOURCE
       //Variables
       public static final String PREFS_NAME = "MyPrefsFile1";
       public CheckBox dontShowAgain;

           final AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
           LayoutInflater adbInflater = LayoutInflater.from(MainActivity.this);
           View eulaLayout = adbInflater.inflate(R.layout.checkbox, null);

           dontShowAgain = (CheckBox) eulaLayout.findViewById(R.id.skip);
           adb.setView(eulaLayout);
           adb.setTitle("Attention");
           adb.setMessage("Your message here");
           adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {


                   SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                   SharedPreferences.Editor editor = settings.edit();
                   editor.putBoolean("skipMessage", dontShowAgain.isChecked());
                   editor.commit();
                   dialog.cancel();
               }
           });

           adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
                   dialog.cancel();
               }
           });
           SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
           Boolean skipMessage = settings.getBoolean("skipMessage", false);
           if (skipMessage.equals(false)) {
               adb.show();
           }





  • Java
  • Android
Share With Your Friends
Share Your Thoughts With Other Users

2 comments so far (post your own)

Ꮃe're a grⲟuρ оf volunteers ɑnd starting
a brand new scheme in our community. Υouг site offered us witһ useful infоrmation to ѡork оn.
You've done аn impressive process аnd our whole neighborhood ѡill be thankful tо you.

Like 0 people liked this.
Reply
Leave a Reply
This small test serves as access restriction against malicious bots.