[英]Dialog context issue - Android
我使用自定义布局创建了一个对话框:
dialog = new Dialog(FetchMenu.this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.custom_dialog_iab);
dialog.show();
我现在正在尝试编辑'layout.custom_dialog_iab'中的文本框,例如:
TextView text = (TextView) findViewById(R.id.all_topics_unlock_button);
text.setText("Purchased");
我的问题:如何获得正确的上下文以便能够编辑文本框?
PS我试过'dialog.getContext()'但仍然继续抛出空指针?
你需要使用:
TextView text = (TextView) dialog.findViewById(R.id.all_topics_unlock_button);
请注意dialog.
在findViewById前面
常规findViewById()将搜索您的活动布局而不是对话框布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.