簡體   English   中英

從警報對話框設置文本

[英]Set text from alert dialog

這是我的代碼:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

            alert.setTitle("What's Your name?");
            alert.setMessage("Seems like you're new here! What's your name?");

            // Set an EditText view to get user input 
            final EditText input = new EditText(this);
            alert.setView(input);

            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

              }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
              }
            });

這將打開一個帶有確定和取消按鈕的編輯文本。

當您單擊確定時,我該怎么做,它將把TextView的文本更改為框內的內容

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                 String newText = input.getText().toString();
                 textView.setText(newText);
            }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM