I want main activity to wait while dialog box is excuted. I tried this.wait(); in main activity but it gives exception. This is all crossed my mind so I am here to ask for help :). Thank you in advance
Any Help Will Be Appreciated
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();
}
}
This is images of this project while executing
http://imageshack.us/photo/my-images/220/11696639.jpg/
In this image you can see Hello World unchanged. I am trying to reflect the change in hello world TextView.
http://imageshack.us/photo/my-images/338/27833231.jpg/
Now in this image. When I hit show dialog it carry on executing the next code TextViewString.setText(Xvalue + Yvalue);
in which it shows the value null
now I want it to wait for dialog box to finish code in which Xvalue and Yvalue will have the value “This n That” by this code
Xvalue = "This ";
Yvalue = "and That";
Move this line:
to your positive button click listener like this: