2012-02-19 87 views
0

在我的android應用程序中,我有一個對話框,用戶在其中輸入信息到EditText並保存數據。到目前爲止,一切正常,直到我將inputType添加到EditTexts。我似乎無法找到解決這個問題的方法,我對android編程和編程一般都比較陌生,所以這可能是一個愚蠢的錯誤,但我無法弄清楚。這裏是一些代碼:添加輸入類型時EditText崩潰

private Dialog dialog() { 
    Dialog diUnit = new Dialog(Overzicht.this); 
    diUnit.setContentView(R.layout.unitdialog); 
    EditText etKM = (EditText) diUnit.findViewById(R.id.etKM); 
    etKM.setInputType(InputType.TYPE_CLASS_NUMBER); 
    diUnit.setTitle("Add unit"); 
    diUnit.setCancelable(false); 
    diUnit.getWindow().getAttributes().width = LayoutParams.FILL_PARENT; 
    bUnitDialogSave = (Button) diUnit.findViewById(R.id.bUnitDialogVoegToe); 
    bUnitDialogCancel = (Button) diUnit.findViewById(R.id.bUnitDialogCancel); 
    bUnitDialogCancel.setOnClickListener(this); 
    bUnitDialogAdd.setOnClickListener(this); 
    return diUnit; 
} 

而且logcat的:

image 1

我知道這不是存儲EditText輸入尚未但是問題只要我添加setInputType行開始。

回答

0

儘量擡高佈局R.layout.unitdialogView(與LayoutInflater),然後搜索在充氣ViewEditText

private Dialog dialog() { 
    Dialog diUnit = new Dialog(Overzicht.this); 
    LayoutInflater inflater = (LayoutInflater) getLayoutInflater(); 
    View content = inflater.inflate(R.layout.unitdialog, null); 
    diUnit.setContentView(content); 
    EditText etKM = (EditText) content.findViewById(R.id.etKM); 
    etKM.setInputType(InputType.TYPE_CLASS_NUMBER); 
    diUnit.setTitle("Add unit"); 
    diUnit.setCancelable(false); 
    diUnit.getWindow().getAttributes().width = LayoutParams.FILL_PARENT; 
    bUnitDialogSave = (Button) diUnit.findViewById(R.id.bUnitDialogVoegToe); 
    bUnitDialogCancel = (Button) diUnit.findViewById(R.id.bUnitDialogCancel); 
    bUnitDialogCancel.setOnClickListener(this); 
    bUnitDialogAdd.setOnClickListener(this); 
    return diUnit; 
+0

感謝您的快速回答,我試圖膨脹的佈局,但我仍然在啓動時崩潰並使用相同的logCat。 – user1219263 2012-02-19 14:19:58

+0

@ user1219263'ttKM.setInputType(InputType.TYPE_CLASS_NUMBER)'是'Overzicht'類中的第64行嗎? – Luksprog 2012-02-19 14:22:26

+0

是的,這是第64行.logCat報告了onCreate方法,其中調用了initialize方法(也在logCat中報告),並在initialize方法內調用了對話方法,在該方法中報告了行「etKM.setInputType InputType.TYPE_CLASS_NUMBER);」 – user1219263 2012-02-19 14:25:46