Android 提示用户输入对话框
Android prompt user input dialog
我想提示用户使用对话框在我的 android 应用程序中给我输入。
当用户放置图形时,它会转到另一个屏幕,但它不会让用户输入它不等待用户直接转到另一个 activity 的值。
我该怎么做才能等待用户输入他需要的值,然后将用户带到他需要的 activity。这是我使用的代码。
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));
}
您没有在等待用户输入。您需要将启动新 activity 的代码放入对话框侦听器中。
放
//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));
}
在确定按钮的 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));
}
}
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));
}
}
把代码放在点击方法里面
我想提示用户使用对话框在我的 android 应用程序中给我输入。 当用户放置图形时,它会转到另一个屏幕,但它不会让用户输入它不等待用户直接转到另一个 activity 的值。 我该怎么做才能等待用户输入他需要的值,然后将用户带到他需要的 activity。这是我使用的代码。
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));
}
您没有在等待用户输入。您需要将启动新 activity 的代码放入对话框侦听器中。
放
//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));
}
在确定按钮的 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));
}
}
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));
}
}
把代码放在点击方法里面