TabHost 和/或 ViewFlipper 对话框问题
我在使用 TabHost
和 ViewFlipper
时遇到一些问题。
这是 ViewFlipper
,因为我希望这个问题的答案也能在 TabHost
中完成这项工作。
我希望在用户达到某个阶段时显示一个自定义对话框,但我无法弄清楚要交给哪个Context
?
final Dialog congratsDialog = new Dialog(MyActivity.this);
congratsDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
congratsDialog.setContentView(R.layout.congrats_dialog);
TextView name = (TextView) congratsDialog.findViewById(R.id.congratsDialogName);
name.setText(player.getName());
这将导致我尝试 setText
的行中出现 NullPointerException
。
我也尝试过 flipper.getContext()
、getBaseContext()
、getApplicationContext()
并且还尝试了其他疯狂的事情,但每次我得到空指针异常
I have some problems with the TabHost
and ViewFlipper
.
Here are the ViewFlipper
as I expect the answer to this will also do the job in the TabHost
.
I would like to have a Custom Dialog shown when the user reach a certain stage, but I can not figure out which Context
to hand it?
final Dialog congratsDialog = new Dialog(MyActivity.this);
congratsDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
congratsDialog.setContentView(R.layout.congrats_dialog);
TextView name = (TextView) congratsDialog.findViewById(R.id.congratsDialogName);
name.setText(player.getName());
This will result in a NullPointerException
in the line were I try to setText
.
I have also tried flipper.getContext()
, getBaseContext()
, getApplicationContext()
and have also tried other crazy thing but every time I get a NullPointerException
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 android 2.0 或更低版本,则将 setContentView() 设置为对话框是在 android 版本上进行权衡,使用 2.0 或更高版本无法使用此功能。否则,如果您想对所有版本执行此操作,请使用 setContentView(View),其中 View 来自 congrats 对话框膨胀后的 xml 布局。
请尝试此操作,如果您有解决方案,请告诉我。
setContentView() to dialog is trade off over android version if you are using android 2.0 or less it would not work use versions 2.0 or above for this function. Otherwise if you want to do for all version then use setContentView(View) where View is from xml layout of congrats dialog after inflating it.
Please try this and let me know if you got solution.