问题标签 [android-viewholder]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2662 浏览

android-listview - 使用 viewHolder 刷新列表视图数据

我正在开发一个具有列表视图的项目,它应该会随着数据库的更改而自动更新,我已经研究了很长时间并找到了一个使用 ViewHolder 模式的解决方案,我尝试了这种方式,它真的很有效!但现在我尝试 manyyyy 解决方案再做一次,它不工作!请帮助我或告诉我是否有使用此模式的提示。真的谢谢!

}

}

0 投票
1 回答
635 浏览

android - 带 ViewHolder 的适配器 - 循环

我的自定义 ListView 适配器有问题。我想使用 ViewHolder(因为我的列表视图有 100 多个元素),但是当我使用我的代码时我的列表视图会循环。通过循环我的意思是它只显示初始位置并循环它们的外观直到列表视图结束。我从这个网站建议:点击

这是我的代码:

有什么想法我做错了吗?我尝试从 if 语句中取出 .setText 和 .setImageResource 并且它可以工作,但是根据这个站点我做错了......你还能给我任何提示如何使列表视图“无延迟”吗?

0 投票
1 回答
211 浏览

android - 具有动态元素数量的 ListView 持有者

这是我面临的问题。我正在开发一个自定义列表视图,其中单个列表视图项由多个文本和图像视图组成。但根据项目属性,有时需要 4 个 TextView,有时 1,有时 6.... 这个数字是动态的,我无法弄清楚如何开发一个合适的视图持有者模式。

我无法通过创建多个 TextView 并在必要时隐藏它们并显示来解决问题,因为我不知道每个项目需要多少个。

并且每次在 getView 中动态地膨胀它们并添加到布局中至少可以说是灾难性的:(

在持有人中拥有一个视图数组列表然后解决问题是一个可行的解决方案吗?

0 投票
1 回答
380 浏览

android - Issue with ViewHolder selection

I am working in an app in which I handle a ListView which is composite with ViewHolder. In this ViewHolder, I have a CheckBox. Here is my code:

What I am doing is stored in SharedPreferences the ViewHolder item values. When I put the tic in any CheckBox it seems that everything is ok, but if I use the scroll, the tick disappears, then I have been investigating and I did the next:

I put this line:

When it is creating the ViewHolder, like this I can get the ID of each ViewHolder, also I added the same line as above inside the listener method:

The thing is that for example when the application starts I can see all the ViewHolder ID, but when I checked in anyone I cans see how the ID is different, so it is taking a different ViewHolder that which I checked, and I do not have idea why take a different ID (ViewHolder).

I made the changes which Sufian told me, this is the code, even so now I get a unfortunatly....

}

I hope this can help to solved the problem

Here is the LogCat:

Finally I resolved the problem this is the code:

`vh.checkCB.setOnCheckedChangeListener(new OnCheckedChangeListener() {

0 投票
4 回答
8923 浏览

android - 如何在带有视图持有者的自定义 ListView 中使用 Button OnClick

我需要一些帮助,我正在使用查看器从动态阵列适配器显示。

我有列表视图。

每行包含 ;

  • 标题(文本视图),
  • 副标题(TextView),
  • 进度条
  • 下载按钮(按钮)。

单击下载按钮时,我想显示进度条并隐藏下载按钮。单击第一行的下载按钮时,显示第一个进度条,但也显示第 8 个进度条。

这是我的代码。我做错了什么?

0 投票
2 回答
919 浏览

android - 按钮在列表视图项目内单击,混合对项目的操作

我有一个带有按钮的列表视图。当我单击按钮时,我希望将整个项目设置为 alpha 值并更改按钮的文本。基本功能(设置 alpha 值和按钮文本更改的项目)有效,但多个列表项因此获得相同的效果。我也尝试在stackoverflow中阅读很多关于此的帖子,但对我没有用。我真的尝试了很多,请帮助。

我的适配器代码如下:

}

0 投票
1 回答
2521 浏览

android - 如何正确实现 ListView 的适配器

我有一个ListViewFragment我想在ListView我从另一个返回时更新数据Activity。我已经覆盖了onResume()中的方法Fragment,修改了中的数据Adapter并调用notifyDataSetChanged()了,Adpater但不知何故ListView没有更新。我怀疑我的 有问题Adapter,但我似乎找不到错误。

这是我的代码Adpater

0 投票
2 回答
672 浏览

android - 具有 2 个布局的适配器中的 ClassCastException

我有一个适配器,它有两个布局(一个用于分隔符,一个用于普通项目),但是当我运行应用程序时,我在 logCat 中得到了这个:

这是我的代码:

0 投票
1 回答
1265 浏览

android - Viewholder 不适用于自定义适配器

下面是用于列表视图的自定义列表适配器的代码。如果我在我的代码中注释掉“not null”标记,即没有我的视图持有者,适配器将完美运行。有人可以帮我解决我在这里遇到的问题吗?

0 投票
1 回答
151 浏览

android - ViewHolder 破坏了 ImageView

我正在为 ListView 使用自定义适配器。基本上它输入三个东西,两个文本视图和一个RelativeLayout。RelativeLayout 用于显示一个颜色块。以前我在下面使用相同的代码,但没有 ViewHolder 的东西,只是使用 findViewById() 从 getView() 方法调用所有内容。这非常有效。我改用 ViewHolder 来加快速度,突然颜色块没有显示。我得到的只是所有文本,因为它应该有一个白色块,颜色块应该是(这很有趣,因为 RelativeLayout 背景的默认颜色设置是黑色)。

这是代码;