Android change context for findViewById to super from inline class

Posted by wuntee on Stack Overflow See other posts from Stack Overflow or by wuntee
Published on 2010-03-12T05:36:14Z Indexed on 2010/03/12 5:47 UTC
Read the original article Hit count: 412

Filed under:
|

I am trying to get the value of a EditText in a dialog box. A the "*"'ed line in the following code, the safeNameEditText is null; i am assuming because the 'findVeiwById' is searching on the context of the 'AlertDialog.OnClickListener'; How can I get/change the context of that 'findViewById' call?

 protected Dialog onCreateDialog(int id) {
  AlertDialog.Builder builder = new AlertDialog.Builder(this);

  switch(id){
   case DIALOG_NEW_SAFE:
    builder.setTitle(R.string.news_safe);
    builder.setIcon(android.R.drawable.ic_menu_add);

    LayoutInflater factory = LayoutInflater.from(this); 
    View newSafeView = factory.inflate(R.layout.newsafe, null);

    builder.setView(newSafeView);
    builder.setPositiveButton(R.string.ok, new AlertDialog.OnClickListener(){
     public void onClick(DialogInterface dialog, int which) {
 *     EditText safeNameEditText = (EditText) findViewById(R.id.new_safe_name);
      String safeName = safeNameEditText.getText().toString();
      Log.i(LOG, safeName);
      setSafeDao(safeName);
     }     
    });

    builder.setNegativeButton(R.string.cancel, new AlertDialog.OnClickListener(){
     public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
     } 
    });
    return(builder.create());
   default:
    return(null);
  }
 }

© Stack Overflow or respective owner

Related posts about android

Related posts about context