0
我想存儲EditText
的輸入並在另一個對話框中顯示它。我怎樣才能做到這一點?如何保存EditText的輸入
所以我有2個活動在其中一個我寫和保存,在另一個我加載它。
public class SaveDialog extends Dialog implements View.OnClickListener{
private MapEditorView mapEditorView;
private Context context;
private Button ok;
private EditText editTextMap;
private boolean exist;
public SaveDialog(Context context, MapEditorView mapEditorView) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.context = context;
this.mapEditorView = mapEditorView;
setContentView(R.layout.dialog_mapeditor_save);
ok = (Button) findViewById(R.id.Button_save_map);
ok.setOnClickListener(this);
exist = true;
}
public void onClick(View v) {
if (v.getId() == ok.getId()) {
if(exist){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Are You sure?");
// set dialog message
alertDialogBuilder
.setMessage("Current map Name will be overwritten!")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
mapEditorView.getEditMapRenderer().reNameMap(
String.valueOf(editTextMap.getText().toString()));
dismiss();
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
else{
mapEditorView.getEditMapRenderer().reNameMap(String.valueOf(editTextMap.getText().toString()));
this.dismiss();
}
}
}
public void setExist(boolean exist) {
this.exist = exist;
}
}