Android对话框不等待TextInput并单击OK
在活动A中,我重写onCreateDialog以创建带有EditText的对话框 在活动A的onCreate中,我调用了一个调用showDialog的方法,然后使用意图生成另一个活动B 我希望用户在EditText中输入一些内容,然后按Ok,然后启动Intent!!。, 但是发生的情况是,对话框弹出,新活动由意图触发 基本上,代码不会在OnClickListener上等待对话框。是因为DialogBox没有停止主UI线程吗??为什么是这样的。我需要做些什么来获得这种等待行为,直到用户在对话框中输入内容并按Ok继续 代码模板Android对话框不等待TextInput并单击OK,android,Android,在活动A中,我重写onCreateDialog以创建带有EditText的对话框 在活动A的onCreate中,我调用了一个调用showDialog的方法,然后使用意图生成另一个活动B 我希望用户在EditText中输入一些内容,然后按Ok,然后启动Intent!!。, 但是发生的情况是,对话框弹出,新活动由意图触发 基本上,代码不会在OnClickListener上等待对话框。是因为DialogBox没有停止主UI线程吗??为什么是这样的。我需要做些什么来获得这种等待行为,直到用户在对话框中输
@Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case DIALOG_TEXT_ENTRY:
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog, null);
return new AlertDialog.Builder(ExampleActivityy.this)
.setTitle(R.string.name_title_string)
.setView(textEntryView)
.setPositiveButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
})
.setNegativeButton(R.string.cancel_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
}
})
.create();
.../...
.../...
...// further down inside onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.mTitleRightImageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent spawnEmptyIntent = new Intent(Intent.ACTION_INSERT, getIntent().getData());
showDialog(DIALOG_TEXT_ENTRY); /// UI does not wait here
onCreateNewList(); // and proceed further to this section
Log.w(TAG, "Intent action string is " + getIntent().getDataString());
startActivity(spawnEmptyListIntent); // and launches this activity.
}
您应该将启动新活动的代码放入相关的onClickListener中。试试这个
.setPositiveButton(R.string.ok_string, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
// User clicked OK so do some stuff
Intent spawnEmptyIntent = new Intent(Intent.ACTION_INSERT, getIntent().getData());
startActivity(spawnEmptyListIntent);
}
})
及
this.mTitleRightImageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
showDialog(DIALOG_TEXT_ENTRY); /// UI does not wait here
onCreateNewList(); // and proceed further to this section
Log.w(TAG, "Intent action string is " + getIntent().getDataString());
}