如何在Android中控制可见性,这是一个错误吗?
当如何在Android中控制可见性,这是一个错误吗?,android,adapter,Android,Adapter,当FeedGroupID!=10,我设置了holder.group\u check.setVisibility(View.GONE),但它仍然显示 适配器代码: if(newFeedModel.getFeedGroupID()!=“10”){ 支架组检查设置可见性(视图可见); holder.tv_uploader_group.setText(newFeedModel.getFeedGroupName()); }否则{ 保持架.组检查.设置可见性(视图.消失); holder.tv_uplo
FeedGroupID!=10
,我设置了holder.group\u check.setVisibility(View.GONE)
,但它仍然显示
适配器代码:
if(newFeedModel.getFeedGroupID()!=“10”){
支架组检查设置可见性(视图可见);
holder.tv_uploader_group.setText(newFeedModel.getFeedGroupName());
}否则{
保持架.组检查.设置可见性(视图.消失);
holder.tv_uploader_group.setVisibility(View.GONE);
}
我得到了这个错误:
尝试调用虚拟方法“void”
空对象引用上的android.widget.TextView.setVisibility(int)“”
为什么会这样
错误-> 支架组检查设置可见性(视图可见);
如果您在holder中的视图已初始化,并且一切正常,没有崩溃,那么问题在于If语句
如果newFeedModel.getFeedGroupID()返回字符串,则使用equals()方法进行比较,如下所示:
if(newFeedModel.getFeedGroupID().equals("10")) {
//perform operations
} else {}
如果在片段中使用,则必须在此方法中调用[override fun(onViewCreated)]
导入…我的布局.view
和我的布局.xml
R.layout.my_layout
在onCreateViewHolder
中是否与my_layout.xml
相同注意:
我的\u布局
仅举个例子。组\u检查为空。请共享您的适配器代码