如何在onClick事件之前更改AlertDialog中的文本

问题描述:

每次加载对话框时,我都无法将某些文本设置为EditText。如何在onClick事件之前更改AlertDialog中的文本

问题是每当出现对话窗口时,editText中应该有一些可编辑的特定文本。它不能被设置为静态的(用XML定义),所以我应该在哪里放置类似wrapper.setText("some phone number etc");的代码?

下面是代码:

private void edit(final long id) { 
    if (id>0) 
    { 
     LayoutInflater inflator = LayoutInflater.from(this); 
     View dialogView = inflator.inflate(R.layout.editonly, null); 
     final editDialogContentGetter wrapper = new editDialogContentGetter(dialogView); 
     new AlertDialog.Builder(this).setTitle(R.string.edit). 
     setView(dialogView).setPositiveButton(R.string.edit,new DialogInterface.OnClickListener(){ 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       basicallyEdit(wrapper); 
      }}).setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener(){ 

       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        Toast.makeText(AllPhones2.this,R.string.nochange,Toast.LENGTH_SHORT).show(); 
       }}).show(); 
    } 
} 
protected void basicallyEdit(editDialogContentGetter wrapper) { 
     // some code here to process information recieved by the dialog 
} 
class editDialogContentGetter 
{ 
    //class for dialog 
    EditText editphoneBox = null; 
    View base2 = null; 
    public editDialogContentGetter(View base2) { 
     // TODO Auto-generated constructor stub 
     this.base2 = base2; 
    } 
    public EditText getEditBoxField() 
    { 
     if(editphoneBox==null) 
    { 
     editphoneBox =(EditText) base2.findViewById(R.id.editphone); 
    } 
     return editphoneBox; 
    } 
    public String getEditBoxText() 
      { 
       return getEditBoxField().getText().toString(); 

      } 

} 

得到它的工作.. 我不得不做的是调用alertdialog对象findViewById()和呼叫的setText有代码是这样

EditText ed=(EditText) editDialog.findViewById(R.id.editphone); ed.setText("1234"); 

谢谢反正