我想通过对话框在我的主屏幕上填充编辑文本。将弹出对话框。用户将输入数据(姓名或电子邮件),然后单击确定。名称和电子邮件应显示在弹出对话框的屏幕上。
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();
}
}
我的 xml 文件必须EditText
在对话框关闭后显示在对话框中输入的数据