0

我正在使用活动。当我点击我的 EditText 时,会出现一个对话框,如下所示: http ://techblogon.com/wp-content/uploads/2013/03/alert-dialog-with-edittext-in-android.png

在我的第一个活动中,如何现在将字符串(我的姓名)从对话框传递到 EditText?这是我的代码:

public class Main extends Activity implements OnItemSelectedListener {

EditText inputName;
Button btnName;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    inputName = (EditText) findViewById(R.id.add_name);

    inputName.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            Dialog();
        }
    });

    // Add Healthcare Button Click event
    btnName.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            final String nameD = inputDoctorName.getText().toString();
            Log.d("TEST","SUCCESS");
        }
    });



}

protected void Dialog()
{
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.layout_dialogbox);
dialog.setTitle("Description de la note");
Button ok = (Button)dialog.findViewById(R.id.btnOK);
ok.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
dialog.dismiss();

}
});
dialog.show();

}
}

你能帮我吗 ?

4

1 回答 1

0

你必须使用SharedPreference来存储字符串并在你的第一个调用它Activity

Activity用_Dialog

private SharedPreferences prefs;
private SharedPreferences.Editor editor;
// Set up our Prefs and Editor
prefs = this.getSharedPreferences("YOURCHOICESTRING", Context.MODE_PRIVATE);
editor = prefs.edit();

//onClick (after the dialog closes and you goto your first Activity)
editor.putString("STRING VARIABLE", "THE STRING YOU WANT TO SAVE");

Activity在您首先要显示从 保存的字符串时使用以下代码Dialog

private SharedPreferences prefs;
private SharedPreferences.Editor editor;
String strImageNum = prefs.getString("STRING VARIABLE", "");
// use strImageNum as you please.
于 2013-10-23T15:07:05.573 回答