我想根据 for 循环生成编辑框的数量,有一个按钮必须调用方法,该方法会将用户输入数据处理到 editbox 中。
据我所知,我无法使用警报对话框,因为它们是异步的并且不会等待用户响应,我可能会使用上面提到的方法并查看行为。并且需要建议和建议。下面的代码可能会提供更多的想法。
for(int x=0;x<vars.size();x++)
{
String get_var=vars.get(x).toString();//get the first item from array
replace(get_var,temp_t);//send the get_var to replace method
}
替换方法的想法是
replace(String get_var,String temp_t)
{
String y=(user input from the textbox, which has to be created dynamically)
if(button pressed) //created dynamically
process(y,temp_t)
}
请建议是否有任何其他更好的解决方法,那么我认为应该像消除按钮并直接处理一样工作[更新]
for(int x=0;x<vars.size();x++)
{
String get_var=vars.get(x).toString();
get_vals_for_xy(get_var, temp_t);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}//end of oncreate method
public void get_vals_for_xy(String get_var,String[][] temp_t) {
System.out.println("value of get_var is " + get_var);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittext = new EditText(this);
alert.setMessage("value is"+get_var);
alert.setTitle("Title");
alert.setView(edittext);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String to_replace = edittext.getText().toString();
show(to_replace);
Toast.makeText(AssignValandFacts.this, to_replace, Toast.LENGTH_SHORT).show();
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
您可以为 for 循环中的每个项目提示对话框并获取用户输入
boolean userResponseReceived=false;
//create a dialog
Dialog dialog=new Dialog(context);
//set dialog content view
//I just assume you have a button in dialog that says OK
Button okButton=(Button)dialog.findViewById(R.id.btnId);
okButton.setOnClickListener(new View.OnclickListener{
@Override
public void onClick(View v){
//userResponseRecieved is a instance variable
userResponseReceived=true;
}
});
for(int x=0;x<vars.size();x++){
//make a while loop to hold the for loop while user inserts data
//make a dialog box and handle user input
dialog.show();
while(!userResponseReceived){}
//continue with the for loop
dialog.dismiss();
userResponseReceived=false;
}