在获取 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() 之前我需要此参考...