我真的找不到问题......
我有一个onOptionItemSelected。
当调用textView.setText时,我得到一个NPE因为findviewbyID不起作用。有什么想法吗?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.latest_detailview_info, null))
.setPositiveButton(R.string.btn_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//do haxx
}
});
TextView textView = (TextView) findViewById(R.id.properties_latest_uploadedby);
textView.setText("NPE");
builder.create();
builder.show();
答案 0 :(得分:1)
尝试添加以下更改。
LayoutInflater inflater=this.getLayoutInflater();
View view=inflater.inflate(R.layout.latest_detailview_info, null);
builder.setView(view)
.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//do haxx
}
});
TextView textView = (TextView) view.findViewById(R.id.properties_latest_uploadedby);
textView.setText("NPE");
builder.create();
builder.show();