Hi Neils,

Why not write the CDialog as it's own Activity, then set the theme to transparent so it looks like a Dialog. Then you can use startActivityForResult() and pass values to/from the new intent.

Just a thought.

Timbobsteve

niels wrote:
For all who dont want to read all the above, here is what i want to:

private boolean makeCDialog() creates a customized Dialog with an
EditText and OK / Cancel.

On pressing ok (so in the OnClickListener) the whole method should
return either TRUE or FALSE. Since the onClickListener is something
like an inner class I think, i cannot return a result. Hopefully you
can understand this..

On Oct 12, 11:52 am, niels <[EMAIL PROTECTED]> wrote:
  
Hi fellow Android fans ;)

Im pretty new to coding with Android and even Java and i am having a
hard time trying to return a result from a private method that holds
an onClickListener. My Activity has two EditText for entering a new
password. On clicking OK the old password should be checked and
entered via a dialog and the new password should be set. My code looks
as following (excerpt):

My Activity calls on click of OK Button the method savePrefs():

private void savePrefs(){
                String pass1 = mTextPass1.getText().toString();
                String pass2 = mTextPass2.getText().toString();

                SharedPreferences settings = getSharedPreferences(FILE, 0);
                SharedPreferences.Editor editor = settings.edit();

                oldpass = settings.getString("Password", null);

                if (pass1.equals(pass2)){                           //EditText
matching?
                        if (oldpass != null) {                           //Old Password
set?

                                if ( makeCDialog() ){                 // allowing setting up new
Password?

                                        editor.putString("Password", pass1);
                                        editor.commit();
                                        Toast.makeText(this,"Set new Password successful", 1).show();
                                } else {
                                    Toast.makeText(this,"No Changes made", 2).show();
                                }

private boolean makeCDialog(){

        // Setting up the dialog
        dia = new Dialog(this);
        dia.setContentView(R.layout.checkpw);
        dia.setTitle("Bitte geben Sie das alte PW ein");

        //Setting up EditText
        pwentry = (EditText) dia.findViewById(R.id.checkpw_entry);
        pwentry.setBackgroundColor(Color.WHITE);
        pwentry.setTextColor(Color.BLACK);

        // Setting up OK and Cancel Button
        Button checkpw_cancel = (Button)
dia.findViewById(R.id.checkpw_cancel);
        Button checkpw = (Button) dia.findViewById(R.id.checkpw);

        checkpw.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View view)
          {
            String checkoldpass = pwentry.getText().toString();

            if (oldpass.equals(checkoldpass)){

                // Allow setting new Password

            } else {

                // Do not allow setting new Password

            }
            dia.dismiss();
          }
        });
        checkpw_cancel.setOnClickListener(new View.OnClickListener(){
                public void onClick(View view){
                        dia.dismiss();
                }
        });
        dia.show();
        }

At the point saying "// Allow setting new Password" the method
makeCDialog should return true, but i cannot call it from within the
onClick. How do I do this or am I going the wrong way?

I was trying to make the makeCDialog() a void method, but then the
actual savePrefs() continues without waiting for the makeCDialog to
set (for example) a boolean.

Thanks for your efforts
    

  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to