0
ダイアログのカスタムレイアウトにTextViewがあります。 ダイアログが表示されようとしているときにそのテキストを変更する必要があります。私は、テキストやショーダイアログを設定するために使用setText()を使用してカスタムレイアウトダイアログのテキストを編集する方法
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/final_score"
/>
Javaコードは
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.its_over, null));
AlertDialog dialog = builder.create();
dialog.show();
TextView t = (TextView)findViewById(R.id.final_score);
t.setText(""+score);
である私も、このコードを試してみました。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.its_over, null));
AlertDialog dialog = builder.create();
TextView t = (TextView)dialog.findViewById(R.id.final_score);
t.setText(""+score);
dialog.show();
これらのメソッドが呼び出されると、アプリケーションがクラッシュする可能性があります。
しかし、我々は
TextView t = (TextView)dialog.findViewById(R.id.final_score);
t.setText(""+score);
を削除する場合はそれがクラッシュしません。
親referanceですか? Logcatは何を出力しますか?なぜそれがクラッシュするかを知ることは重要です。その後、私たちはさらに助けてくれるでしょう。それは私に見えます、それはnull参照かもしれない、 'TextView t =(TextView)dialog.findViewById(R.id.final_score); 'ヌルを返しますか? –