gpt4 book ai didi

android - ListView 项目中的 SeekBar 已重置

转载 作者:搜寻专家 更新时间:2023-11-01 07:58:59 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个带有自定义项目 View 的 ListView。每个 Item 都有一个自己的 SeekBar,其中包含显示在 ListView 中的不同 Persons 的年龄。我的问题是我可以为每个人滚动 SeekBar,但是如果下次将 SeekBar 重置为 0 时,该项目滚出并进入。我的 CustomAdapter 如下所示:

public View getView(int position, View convertView, ViewGroup parent) 
{
View row = convertView;
PeopleHolder holder = null;

if(row == null)
{
LayoutInflater inflater = LayoutInflater.from(context);
row = inflater.inflate(layoutResourceId, parent, false);

holder = new PeopleHolder();

final TextView tvAge = (TextView) row.findViewById(R.id.Age);
tvNote.setTag(position);

holder.age = (SeekBar) row.findViewById(R.id.agekBar);
holder.age.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar){ }

@Override
public void onStartTrackingTouch(SeekBar seekBar){ }

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
tvAge.setText("" + progress);
}
});

holder.name = (TextView) row.findViewById(R.id.Name);
row.setTag(holder);
}
else
{
holder = (PeopleHolder) row.getTag();
}

People p = data.get(position);

holder.name.setText(p.getFullName());
holder.age.setProgress(p.getAge());

return row;
}

private static class PeopleHolder
{
TextView name;
SeekBar age;
}

最佳答案

一定要在进度改变的时候改变人物年龄的值:

    // adding a final int that can be accessed from inside the listener
final int personPosition = position;
holder.age.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
...

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
tvAge.setText("" + progress);
// change the age of the person in data
data.get(personPosition).setAge(progress);
}
});

关于android - ListView 项目中的 SeekBar 已重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24100409/

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