0

次のような警告ダイアログがあります。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);
    EditText input = new EditText(this);
    input.setText(sp.getString("NAME_0",""),TextView.BufferType.EDITABLE);
    alertDialogBuilder.setView(input);
    String name = input.getText().toString();
    alertDialogBuilder.setCancelable(false);
    alertDialogBuilder.setTitle("Enter your name"); //Set the title of the box
    //alertDialogBuilder.setMessage(""); //Set the message for the box
    alertDialogBuilder.setPositiveButton("Start", new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int id){
            dialog.cancel(); //when they click dismiss we will dismiss the box
        }
    });
    AlertDialog alertDialog =alertDialogBuilder.create(); //create the box
    alertDialog.show(); //actually show the box

そして問題は、'name' が常に空のように見えることです。警告ダイアログ内にある編集テキストからテキストを取得する別の方法はありますか?

4

2 に答える 2

2

メソッドはうまく機能します。変数を割り当てるのが早すぎるだけです。たとえば、ユーザーが onClick() 内のボタンをクリックしたときにそれを行う必要があります。

于 2013-07-01T19:46:02.083 に答える