0

I have EditText in an AlertDialog, it is used for editing data fetched from a cursor. before editing, I want to show old data in the EditText. The following method is called from a ContextMenu item:

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();
}

I think it should be set before the dialog is created, so I have tried to move that statement elsewhere, but failed.

4

0 に答える 0