Question

I have created a button "settings", when i click in, a dialog dispaly for authentication. I just make a test, if the edit text is empty the dialog dismiss else another dialog box display which contains a spinner. Here's the code:

case R.id.bsettings:

            // Create Object of Dialog class
            final Dialog login = new Dialog(MainActivity.this);
            // Set GUI of login screen
            login.setContentView(R.layout.login_dialog);
            login.setTitle("Settings connection");

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btn_set_Login);
            Button btnCancel = (Button) login.findViewById(R.id.btn_set_Cancel);
            final EditText Id = (EditText)login.findViewById(R.id.id_setting);
            final EditText txtPassword = (EditText)login.findViewById(R.id.Password_setting);
            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if(Id.getText().toString().trim().length() > 0 && txtPassword.getText().toString().trim().length() > 0)
                    {
                    // Validate Your login credential here than display message
                    Toast.makeText(MainActivity.this,
                            "Login Sucessfull", Toast.LENGTH_LONG).show();

                    // Redirect to dashboard / home screen.
                    login.dismiss();

                    final Dialog settingdialog = new Dialog(MainActivity.this);

                    settingdialog.setContentView(R.layout.setting_dialog);
                    settingdialog.setTitle("Settings Menu");
                    spinner = (Spinner)findViewById(R.id.languagespinner);



                    ArrayAdapter<String>adapter = new ArrayAdapter<String>(MainActivity.this,
                            android.R.layout.simple_spinner_item,language);

                    spinner.setAdapter(adapter);
                    settingdialog.show();

                    }
                    else
                    {
                        Toast.makeText(MainActivity.this,
                                "Please enter Username and Password", Toast.LENGTH_LONG).show();

                    }
                }
            });
            btnCancel.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    login.dismiss();
                }
            });

            // Make dialog box visible.
            login.show();
            login.getWindow().setGravity(Gravity.TOP);

            break;

The problem is when i click in a login button the second dialog didn't display. Should you tell me what's wrong in my code ?

Was it helpful?

Solution

You find the spinner directly. Chanage

spinner = (Spinner)findViewById(R.id.languagespinner);

to

spinner = (Spinner)settingdialog.findViewById(R.id.languagespinner);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top