TextView、SeekBar、およびその他のウィジェットで参照を取得する際に奇妙な問題があります。私の AlertDialog は次のようになります。
public class LineDialog extends AlertDialog {
private static SeekBar seekBar1, seekBar2, seekBar3;
private static TextView textView1, textview2, textView3;
protected LineDialog(final Context context, final DrawView drawView) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogLayout = inflater.inflate(R.layout.line_dialog, null);
setView(dialogLayout);
setTitle("Line properties");
textView1 = (TextView) findViewById(R.id.textView1); // TODO Code crash here :(
setButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
seekBar1 = (SeekBar) findViewById(R.id.seek1);
// some other code...
}
});
}
Lineで参照を取得したいときは
textView1 = (TextView) findViewById(R.id.textView1);
Logcat からエラーが送信されます
requestFeature() must be called before adding content
しかし、LineDiealog(AlertDialog) の onClick() メソッドで参照を取得すると、すべて正常に動作します。LineDialog.show() が呼び出される前にこの参照が必要なため、残念ながらこれは遅すぎます...