在自定义对话框中设置textview [英] set textview in custom dialog
本文介绍了在自定义对话框中设置textview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个自定义对话框,但是无法从Java设置对话框布局中的文本视图中的文本,并且程序崩溃。我的错误是什么?
I have created a custom dialog but I cannot set a text into the textview that is in the dialog layout from java and my program crashes. what is my mistake?
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();
}
}时,我取消了该行程序的工作,但我需要设置文本
} when I deleat this line program work but i need to set text
titel.setText("RBC");
推荐答案
更改
TextView titel = (TextView) findViewById(R.id.dialog_edit_text_title);
至
TextView titel = (TextView) dialog.findViewById(R.id.dialog_edit_text_title);
这篇关于在自定义对话框中设置textview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文