wanna get back any value after closing Alert Dialog

Put your problem here if it does not fit any of the other categories.

wanna get back any value after closing Alert Dialog

Postby soclose » Tue Jun 29, 2010 10:21 am

Hi,

I use Alert Dialog as Login. So after closing this dialog, any value assigned at dialog show() is lost. how to get back this value? my code is below

Code: Select all
   private void accessPinCode()
   {
      LayoutInflater factory = LayoutInflater.from(this);
      final View textEntryView = factory.inflate(R.layout.dialog_login, null);
      AlertDialog.Builder alert = new AlertDialog.Builder(this);                 
      alert.setTitle("Title"); 
      alert.setMessage("Enter Pin :");              
      alert.setView(textEntryView);      

      alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) {         
            EditText mUserText;
            mUserText = (EditText) textEntryView.findViewById(R.id.txt_password);
            //String strPinCode = mUserText.getText().toString();
            Log.d( TAG, "Pin Value 1 : " + mUserText.getText().toString());               
            strPIN = mUserText.getText().toString();
            Log.d( TAG, "strPIN inside accessPinCode : " + strPIN);
            fPIN= checkPINCode();
            Log.d( TAG, "fPass : " + fPIN);

            
            return;                  
         } 
      }); 

      alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

         public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            return;   
         }
      });

      alert.show();
      Log.d( TAG, "strPIN outside Alert Show : " + strPIN);
   }


Based on my code, strPIN and FPIN values are lost. I wanna use those value outside accessPinCode function. how to get?

Thank you.
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Top

Re: wanna get back any value after closing Alert Dialog

Postby ranjandeo » Tue Jun 29, 2010 1:32 pm

I think, u should take a global variable and set its value inside the alert dialog instead of returning it.
Ranjan Deo
User avatar
ranjandeo
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon May 31, 2010 6:20 am
Location: Kolkata, India

Re: wanna get back any value after closing Alert Dialog

Postby soclose » Tue Jun 29, 2010 2:27 pm

These two values, strPIN and fPIN, are global var. All these values are null and false outside accessPinCode function. that's a problem.
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Re: wanna get back any value after closing Alert Dialog

Postby soclose » Wed Jun 30, 2010 3:04 am

Actually, I call this function at tabchanged event. If login pass, the user could access another tab. But all've already worked in tab changed event before clicking AlertDialog's Ok button. My tab event like below

Code: Select all
    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
             
             public void onTabChanged(String tabId) {
                // TODO Auto-generated method stub
                
                if (tabId.equals("index"))
                {
                       tabHost.setCurrentTab(1);
                       accessPinCode();
                }
                Log.d( TAG, "tabId : "+ tabId );   
             }
          });



Is there any type of Dialog suitable for Login? How to solve?
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Re: wanna get back any value after closing Alert Dialog

Postby anarche » Wed Jun 30, 2010 3:16 am

Subclass AlertDialogue with two extra getters (one for each variable), and add the creating Activity as the onDismissListener.

onDismiss is called and finishes before the Dialogue is disposed of and you will have access to the variables.

You do not need to use global variables.
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: wanna get back any value after closing Alert Dialog

Postby soclose » Wed Jun 30, 2010 3:25 am

Thank Anarche. May I get a sample of OnDismissListener.
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Top

Re: wanna get back any value after closing Alert Dialog

Postby soclose » Wed Jun 30, 2010 4:01 am

Finally, instead of calling accessPinCode inside Tab OnChanged event, I put all alertDialog creating inside this event. Because I wanna set current tab if login pass. Thank you all.
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 21 guests