安卓的setText()用于TextView的在PopupWindow不工作 [英] Android: setText() for TextView in PopupWindow not working

查看:938
本文介绍了安卓的setText()用于TextView的在PopupWindow不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有,我用了一个PopupWindow布局一个TextView。我表明,当用户点击一个按钮,这个PopupWindow;我希望能够在点击按钮来动态更改PopupWindow文本。然而,findViewById(my_textview).setText()似乎并没有做任何事情,确实会导致PopupWindow当我按一下按钮不再显示。

Basically, I have a TextView in a layout which I use for a PopupWindow. I show this PopupWindow when a user clicks a button; I want to be able to dynamically change the text in the PopupWindow upon button click. However, findViewById(my_textview).setText() does not seem to do anything, and indeed causes the PopupWindow to no longer show when I click the button.

我可以设置从布局XML精细的文本。

I can set text from the layout xml fine.

任何人都知道什么是这个吗?谢谢 -

Anyone know what's up with this? Thanks-

推荐答案

我解决了这个问题。不管什么原因,你需要调用popup.getContentView()。findViewById,而不是仅仅findViewById(其中弹出你PopupWindow对象)。我没有得到一个NullPointerException异常之前,所以我不知道是什么原因这个固定的问题,但它没有。

I solved the problem. For whatever reason you need to call popup.getContentView().findViewById instead of just findViewById (where popup is your PopupWindow object). I wasn't getting a NullPointerException before so I'm not exactly sure why this fixed the issue but it did.

所以,code是这样:

So the code goes something like:

PopupWindow PW =新PopupWindow(你的布局,而params这里);

PopupWindow pw = new PopupWindow(your layout and params here);

((TextView中)pw.getContentView()findViewById(R.id.my_textview)。)的setText(你好有);

((TextView)pw.getContentView().findViewById(R.id.my_textview)).setText("hello there");

pw.showAtLocation(您PARAMS这里);

pw.showAtLocation(your params here);

这篇关于安卓的setText()用于TextView的在PopupWindow不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆