0
我用下面的代碼的setView對話框:如何在對話框的setView在Android
LayoutInflater inflater = LayoutInflater.from(this);
View layout = inflater.inflate(R.layout.mylayout, null);
TextView MyTextView = (TextView)findViewById(R.id.my_tv);
MyTextView.setText("test");
AlertDialog MyDialog;
AlertDialog.Builder MyBuilder = new AlertDialog.Builder(this);
MyBuilder.setTitle("title");
MyBuilder.setView(layout);
MyDialog = MyBuilder.create();
MyDialog.show();
my_tv是mylayout.xml一個TextView。
但它在行MyTextView.setText("test");
處發生NullPointer錯誤。
我該如何修改它?