Reputation: 25
I want to fill the edit text on my main screen via dialog. The dialog will pop up.user will enter the data (name or email) and the click ok. The name and email should be dispalyed on the screen on which the dialog poped up..
public class DialogActivity extends Activity
{
/* Called when the activity is first created.*/
final Context context = this;
//private Button button;
String result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
final Dialog dialog = new Dialog(DialogActivity.this);
dialog.setContentView(R.layout.main);
dialog.setTitle("I'm soo ");
dialog.setCancelable(true);
dialog.show();
Button okButton = (Button) dialog.findViewById(R.id.button1);
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LayoutInflater factory = LayoutInflater.from(DialogActivity.this);
final EditText barFirst= (EditText) dialog.findViewById(R.id.edittext01);
final EditText barSecond= (EditText) dialog.findViewById(R.id.edittext02);
result = barFirst.getText().toString();
dialog.hide();
}
});
EditText tview = (EditText)findViewById(R.id.cat_id);
tview.setText(result);
Toast.makeText(this, result,Toast.LENGTH_LONG).show();
}
}
my xml file has to EditText
that want to display the data being entered in the dialog after the dialog is closed
Upvotes: 2
Views: 1885
Reputation: 506
public class DialogActivity extends Activity {
/* Called when the activity is first created.*/
final Context context = this;
//private Button button;
String result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Dialog dialog = new Dialog(DialogActivity.this);
dialog.setContentView(R.layout.main);
dialog.setTitle("I'm soo ");
dialog.setCancelable(true);
dialog.show();
Button okButton = (Button) dialog.findViewById(R.id.button1);
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LayoutInflater factory = LayoutInflater.from(DialogActivity.this);
final EditText barFirst= (EditText) dialog.findViewById(R.id.edittext01);
final EditText barSecond= (EditText) dialog.findViewById(R.id.edittext02);
result = barFirst.getText().toString();
dialog.dismiss();
EditText tview = (EditText)findViewById(R.id.cat_id);
tview.setText(result);
}
});
Upvotes: 1