AlertDialog中的EditText不能是setText

时间:2013-10-25 10:27:10

标签: android android-edittext android-alertdialog

我在EditText中有AlertDialog,它用于编辑从游标获取的数据。在编辑之前,我想在EditText中显示旧数据。从ContextMenu项目调用以下方法:

private void edit(final long rowId){
   LayoutInflater inflater = LayoutInflater.from(this);
   final View editView = inflater.inflate(R.layout.add_dialog,null);
   new AlertDialog.Builder(this)
      .setTitle("Edit: " + cursor.getString(1))
      .setView(editView)
      .setPositiveButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
         EditText nameView = (EditText)editView.findViewById(R.id.nameView);
         //why the following statement can't work?
         nameView.setText(cursor.getString(1));
         editData(rowId, nameView.getText().toString());
      }
   })
   .setNegativeButton("Cancel",null)
   .show();
}

我认为应该在创建对话框之前设置它,所以我试图将该语句移到别处,但是失败了。

0 个答案:

没有答案