gpt4 book ai didi

java - 想要 Android 中的程序方法

转载 作者:行者123 更新时间:2023-12-02 07:50:51 24 4
gpt4 key购买 nike

我希望主要 Activity 在执行对话框时等待。我在主要 Activity 中尝试了 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 没有变化。我试图反射(reflect) 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";

最佳答案

移动此行:

TextViewString.setText(Xvalue + Yvalue);

像这样的积极按钮点击监听器:

public void onClick(DialogInterface dialog, int whichButton) {
// THIS TO BE EXECUTE FIRST
Xvalue = "This ";
Yvalue = "and That";
/* User clicked OK so do some stuff */
TextViewString.setText(Xvalue + Yvalue);
}

关于java - 想要 Android 中的程序方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10251408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com