我创建了一个自定义对话框,但我无法将文本设置到 java 对话框布局中的 textview 中,并且我的程序崩溃了。我的错误是什么?
public class Total_CBC extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.total_cbc);
final TextView RBC_T = (TextView) findViewById(R.id.total_cbc_text_rbc);
Button RBC_B = (Button) findViewById(R.id.total_cbc_btn_rbc);
//
RBC_B.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showCustomDialog(RBC_T);
}
});
}
protected void showCustomDialog(final TextView _RBC_T) {
final Dialog dialog = new Dialog(Total_CBC.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_edit);
final EditText editText = (EditText) dialog.findViewById(R.id.dialog_edit_edittext);
Button button = (Button) dialog.findViewById(R.id.dialog_edit_btn);
TextView titel = (TextView) findViewById(R.id.dialog_edit_text_title);
titel.setText("RBC");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
_RBC_T.setText(editText.getText().toString());
dialog.dismiss();
}
});
dialog.show();
}
} 当我删除这行程序的工作,但我需要设置文本
titel.setText("RBC");