Android提示用户输入对话框

时间:2015-08-18 11:19:23

标签: java android dialog

我想提示用户使用对话框在我的Android应用程序中输入。 当用户放置图形时,它将转到另一个屏幕,但它不会让用户输入它不会等待用户直接转到另一个活动的值。 我该怎么做才能让用户输入他需要的值,之后用户可以进行他需要的活动。这是我使用的代码。

else
  {
   {
    // get prompts.xml view
    LayoutInflater layoutInflater = LayoutInflater.from(Login.this);
    View promptView = layoutInflater.inflate(R.layout.activity_input_dialog, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Login.this);
    alertDialogBuilder.setView(promptView);

    final EditText editText = (EditText) promptView.findViewById(R.id.editCodeSurvey);
    // setup a dialog window
    alertDialogBuilder.setCancelable(false)
     .setPositiveButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
        String surveyCode = editText.getText().toString();
                                            }
                                        })
     .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                                                        dialog.cancel();
                                                    }
                                                });
    // create an alert dialog
   AlertDialog alert = alertDialogBuilder.create();
   alert.show();
   }
   //After Creating Dialog then we asking if the User that signed in is a manager
   if(parseUser.getBoolean("isManager"))
   {
    //open manager Class
    startActivity(new Intent(Login.this,ManagerScreen.class));
   }
   else{
    //open Student Class to fill the survey
    startActivity(new Intent(Login.this,StudentField.class));
    }

2 个答案:

答案 0 :(得分:0)

您不是在等待用户输入。您需要在对话框侦听器中放置启动新活动的代码。

//After Creating Dialog then we asking if the User that signed in is a manager
if(parseUser.getBoolean("isManager"))
{
    //open manager Class
    startActivity(new Intent(Login.this,ManagerScreen.class));
}
else{
    //open Student Class to fill the survey
    startActivity(new Intent(Login.this,StudentField.class)); 
}

在OK按钮的onClick内。它应该是这样的

public void onClick(DialogInterface dialog, int id) {
    String surveyCode = editText.getText().toString();
    //After Creating Dialog then we asking if the User that signed in is a manager
    if(parseUser.getBoolean("isManager"))
    {
        //open manager Class
        startActivity(new Intent(Login.this,ManagerScreen.class));
    }
    else{
        //open Student Class to fill the survey
        startActivity(new Intent(Login.this,StudentField.class)); 
    }
}

答案 1 :(得分:0)

public void onClick(DialogInterface dialog, int id) {
    String surveyCode = editText.getText().toString();

    if(parseUser.getBoolean("isManager")) {
        //open manager Class
        startActivity(new Intent(Login.this,ManagerScreen.class));
    } else {
        //open Student Class to fill the survey
        startActivity(new Intent(Login.this,StudentField.class));
    }
}

将代码放在click方法