android适配器行隐藏

标签 android adapter

在 arrayAdptor 中,我们使用以下代码:

 final LayoutInflater inflater = activity.getLayoutInflater();
    row = (LinearLayoutCustom) inflater.inflate(R.layout.row, null);
    final TextView label = (TextView) row.findViewById(R.id.title);
    label.setText(position + "" + items[position]); 
    return row;

现在假设某些值为空(例如在位置 2 , items[2] = null )所以我不想在行中显示它。我想隐藏它。如果我使用

               row.setVisibility(View.GONE) 

它在这一行留下了一个我不想要的空白。那我该怎么办?

最佳答案

据我所知,您不能从 getView 返回空 View ,但您可以使 View 不可见且高度为 1。尽管使用 getCount 进行操作可能是首选方式。

view.setVisibility(View.INVISIBLE);
view.getLayoutParams().height = 1;

关于android适配器行隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6907891/

相关文章:

android - 列表适配器中的复选框行为异常

android - getItem(getCount() - getPosition() -1) 是如何工作的

android - 我正在尝试创建一个 webview Activity ,但未加载整个网站

android - Mongoose 和 Android Volley

java - 应用程序在加载 xml 布局文件的主线程中做太多工作

android - PagerAdapter 的 instantiateItem(ViewGroup container, int position) 方法的一些困惑

android - 如何在Android Kotlin上增加动态布局?

android - 在适配器内进行一些网络操作

android - 如何从 firebase 下载 pdf 并从我的应用程序目录访问它?

java - Joda Time 不能减去一小时