android – 在自定义对话框中设置textview

android – 在自定义对话框中设置textview,第1张

概述我已经创建了一个自定义对话框,但我无法将文本设置为 java中对话框布局中的textview,程序崩溃.我的错是什么? public class Total_CBC extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceS 我已经创建了一个自定义对话框,但我无法将文本设置为 java中对话框布局中的textvIEw,程序崩溃.我的错是什么?
public class Total_CBC extends Activity {@OverrIDeprotected 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");
解决方法 更改
TextVIEw titel = (TextVIEw) findVIEwByID(R.ID.dialog_edit_text_Title);

TextVIEw titel = (TextVIEw) dialog.findVIEwByID(R.ID.dialog_edit_text_Title);
总结

以上是内存溢出为你收集整理的android – 在自定义对话框中设置textview全部内容,希望文章能够帮你解决android – 在自定义对话框中设置textview所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1141075.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存