lundi 20 février 2017

Using Dialogs in If else statement contained in For Loop

I'm newbie to android programing I got problem in using a for loop having containing dialogue. These is my code

for (String s:mArray)
                {
                    if (s.equals(store))
                {

                        Intent intent = new Intent(MainActivity.this, c1Activity.class);
                        startActivity(intent);
                        break;
                    }
                    else 
                    {

                        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                        builder.setTitle("Alert!");
                        builder.setMessage("The User ID is wrong !");
                        builder.setCancelable(true);
                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id)
                                {
                                    //do things
                                }
                            });
                        AlertDialog alert = builder.create();
                        alert.show();

                    }
                }

Programs checks whether the user enters a given value which are in array.xml in array name db. When the user enters a wrong no it popups a dialogue but when he enters correct userID It open next activity with opening dialogue After opening a dialogue only it opens next activity. It depend on the position of value in array if its the fisrt one no dialogu coming but if its a second one one dialogue appears similarly for all.

Aucun commentaire:

Enregistrer un commentaire