我希望主要活动在执行对话框时等待。我尝试this.wait();
了主要活动,但它给出了例外。这都是我的想法,所以我在这里寻求帮助:)。提前感谢您的任何帮助将不胜感激
public class MyDailogTestActivity extends Activity {
/** Called when the activity is first created. */
String Xvalue,Yvalue;
TextView TextViewString;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ShowDialog = (Button) findViewById(R.id.ShowDialog);
TextViewString = (TextView) findViewById(R.id.ShowDialogText);
ShowDialog.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
Dialog MyDialog = MyDailog();
MyDialog.show();
// I WANT THIS TO EXECUTE AFTER BELOW MENTIONED CODE
TextViewString.setText(Xvalue + Yvalue);
}
});
}
private Dialog MyDailog(){
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.my_dialog, null);
return new AlertDialog.Builder(MyDailogTestActivity.this)
.setTitle("Enter Value")
.setView(textEntryView)
.setPositiveButton("Oky", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// THIS TO BE EXECUTE FIRST
Xvalue = "This ";
Yvalue = "and That";
/* User clicked OK so do some stuff */
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
}
})
.create();
}
}
这是该项目在执行时的图像
http://imageshack.us/photo/my-images/220/11696639.jpg/ 在这张图片中你可以看到 Hello World 没有改变。我试图反映 hello world TextView 的变化。
http://imageshack.us/photo/my-images/338/27833231.jpg/
现在在这张图片中。当我点击显示对话框时,它继续执行下一个代码TextViewString.setText(Xvalue + Yvalue);
,其中显示值为 null 现在我希望它等待对话框完成代码,其中 Xvalue 和 Yvalue 将通过此代码具有值“This n That”
Xvalue = "This ";
Yvalue = "and That";