我已经构建了自己的适配器,它可以扩展我创建的自定义 View 。该 View 包含与作者关联的 TextView 标记。
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="John Smith" />
我的问题是,当我去填充该 View 时,即使我从中加载数据的对象(currentStory)包含非空值,它仍然不会填充。
if (currentStory.getAuthor() == null)
holder.author.setVisibility(TextView.GONE);
else
holder.author.setText(currentStory.getAuthor());
在调试代码时,我在上述条件之后检查对象及其状态,并且 Text 属性填充了正确的数据。当我让它运行时,它没有显示正确的内容。
有人知道我可能做错了什么或错过了什么吗?
最佳答案
我不确定这是否可以解决您的问题,但请尝试一下
holder.author.post(new Runnable() {
@Override
public void run() {
if (currentStory.getAuthor() == null)
holder.author.setVisibility(TextView.GONE);
else
holder.author.setText(currentStory.getAuthor());
}
});
关于java - 使用 textview 更新文本时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39050738/