Skip to content Skip to sidebar Skip to footer

Android Get Alert Dialog Default Selected Item

I have a little problem with setting the default selected item in Alert Dialog. Here is what I use in my code : if(memory>megAvailable){ selected = 0; } else if(megA

Solution 1:

You can just put the code that sets your storagePath in the onClickHandler attached to the NegativeButton:

final int defaultSelected = selected +1; //this is final since you need to access it in the anonymous inner class; we're adding 1 since your value that you write seems to be either 1 or 2.
 builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
                mHandlerUpdateUi.post(mUpdateUpdateUi);     
                editor.putInt("storagePath", defaultSelected);
                editor.commit();
        }
        });

Post a Comment for "Android Get Alert Dialog Default Selected Item"