2014-07-20 59 views
0

我在這個方法得到一個錯誤:「構造對象(EditText上)是不確定的」錯誤:構造對象(EditText上)是未定義

private void setupAlert() 
    { 
     Log.d(TAG, "setupAlert()"); 
     LayoutInflater li = LayoutInflater.from(this); 
     View promptsView = li.inflate(R.layout.emaildialog, null); 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 
     alertDialogBuilder.setView(promptsView); 
     final EditText userInput = (EditText)promptsView.findViewById(R.id.editTxtEmailAddress); 
     alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() 
     { 
      public void onClick(DialogInterface dialog, int id) 
      { 
       updatePref(userInput.getText().toString()); 
       Log.d(MainActivity.TAG, "setupAlert: getPreference()=" + getPreference()); 
       takeSnapNow(); 
      } 
     }); 
     AlertDialog alertDialog = alertDialogBuilder.create(); 
     alertDialog.show(); 
    } 

protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.colour_selector); 
     Log.d(TAG, "onCreate: getPreference()=" + getPreference()); 
     if (getPreference().equals("")) { 
      setupAlert(); 
      takeSnapNow(); 
     } else { 
      takeSnapNow(); 
     } 
    } 

private void takeSnapNow() 
    { 
     String fileName = "TempImage.jpg"; 
     ContentValues values = new ContentValues(); 
     values.put(MediaStore.Images.Media.TITLE, fileName); 
     values.put(MediaStore.Images.Media.DESCRIPTION, "Captured by XYZ app"); 
     imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
     intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 
     startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 
    } 

請建議,要解決這個錯誤。

編輯:通過刪除其他人建議的UserInput來糾正上述錯誤。但是alertDialog仍然沒有顯示。邏輯是首先在onCreate中檢查sharedpref,如果找不到,則調用setupAlert()方法從用戶獲取電子郵件ID。 任何線索?更改了以上代碼段中更新的代碼。

回答

1

DialogInterface.OnClickListener不採取EditText作爲構造函數的參數,你不需要做!你可以使用userInput沒有將它傳遞給DialogInterface.OnClickListener,只是用它作爲跟隨

alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { 
+0

當上述方法被擊中不被顯示的alertDialog。任何線索? – webgenius

+0

你可以用新的編輯更新你的問題中的代碼 –

+0

現在一切正常,你的方法中沒有錯誤,你調用了這個方法嗎? –

0

爲什麼你使用「新的DialogInterface.OnClickListener(userInput)」?

只需使用新DialogInterface.OnClickListener()

相關問題