gpt4 book ai didi

android - 在不丢失 SeekBar 焦点的情况下更新 ListView 行

转载 作者:行者123 更新时间:2023-11-30 03:49:03 25 4
gpt4 key购买 nike

我有一个包含一行项目的 ListView,其中每一行都包含一个 SeekBarTextView。每当我移动任何 SeekBar 时,我都需要实时更新 ListView 中的所有 TextView,而不会失去对SeekBar.

我试过了

  • ListView 上调用 notifyDataSetChanged(),但是SeekBar 失去焦点。

  • 使用以下代码遍历 ListView:

for (int i = 0; i < listView.getChildCount(); i++)
{
TextView tv = (TextView) listView.getChildAt(i).findViewById(R.id.textView1);
String value = getData();
tv.setText(value);
}

但是,上面的代码并没有对 ListView 进行持续更新,如果用户滚动,这是一个问题。

有什么建议可以解决这个问题吗?

最佳答案

Whenever I move any of the SeekBar's I need to have all the TextView's in the ListView updated live, without losing focus on the SeekBar.

您要做的是在不调用 notifyDataSetChanged() 的情况下更新适配器的数据列表,然后还更新当前可见行的 TextViews

//...
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// found is a reference to the ListView
int firstVisible = found.getFirstVisiblePosition();
// first update the mData which backs the adapter
for (int i = 0; i < mData.size(); i++) {
// update update update
}
// update the visible rows
for (int j = 0; j < found.getChildCount(); j++) {
final View row = found.getChildAt(j);
// get the position from the mData by offseting j with the firstVisible position
((TextView) row.findViewById(R.id.theIdOfTheTextView)).setText(mData.get(firstVisible + j));
}
}
//...

这应该会为您提供顺利的更新。

关于android - 在不丢失 SeekBar 焦点的情况下更新 ListView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14450389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com