2012-02-19 12 views
0

私のアンドロイドアプリケーションでは、ユーザーがEditTextに情報を入力してデータを保存するダイアログボックスがあります。これまでのすべては、inputTypeEditTextsに追加するまでうまくいきました。私はこの問題の解決策を見つけることができないようだ、私はむしろアンドロイドプログラミングとプログラミング全般に新しいので、それは間違ったミスかもしれないが、私はそれを把握することはできません。ここでは、コードの一部:入力タイプを追加すると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

LayoutInflaterで)ViewにレイアウトR.layout.unitdialogを膨らませると、その後膨張ViewにそのEditTextを検索してみてください:あなたの迅速な答えを

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

おかげで、私はレイアウトを膨らませることを試みたが、まだI起動時と同じlogCatでクラッシュする。 – user1219263

+0

@ user1219263 'ttKM.setInputType(InputType.TYPE_CLASS_NUMBER)'は 'Overzicht'クラスの64行ですか? – Luksprog

+0

はい、それは64行目です。logCatは、initializeメソッドが呼び出されるonCreateメソッド(logCatにも報告されます)とinitializeメソッドの中で、ダイアログメソッドが呼び出されて「etKM.setInputType InputType.TYPE_CLASS_NUMBER); " – user1219263

関連する問題