2010-10-02 75 views
0

如何從onClick方法返回字符串值?Android:從對話框返回數據

public class DialogWithInputBox extends Activity { 
       /** Called when the activity is first created. */ 
       @Override 
       public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 

        final AlertDialog.Builder alert = new AlertDialog.Builder(this); 
        final EditText input = new EditText(this); 
        alert.setView(input); 
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) { 
          String value = input.getText().toString().trim(); 

         } 
        }); 

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

       } 
      } 

回答

0

我再回答我的問題),onClick - 不希望改變不是最終數據,我創建final List<String>(他讓你改變他),並在onClick使用list.add(value)

相關問題