我有一个带有范围搜索栏的列表视图,我正在添加它以选择视频中文本叠加的持续时间。当我动态添加多个搜索栏时,只有最后一个搜索栏更改才能在arraylist中正确反映,其他搜索栏的值不会更新。
适配器代码:
public class TextAdapter extends ArrayAdapter<TextDetails> {
private List<TextDetails> dataSet;
Context mContext;
private int lastPosition = -1;
public TextAdapter(List<TextDetails> td, Context applicationContext) {
super(applicationContext,R.layout.list_edit, td);
this.dataSet=td;
this.mContext=applicationContext;
}
private static class ViewHolder {
TextView txtName;
CrystalRangeSeekbar sk;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent){
// Get the data item for this position
final TextDetails data = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
final ViewHolder viewHolder; // view lookup cache stored in tag
final View result;
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_edit, parent, false);
viewHolder.txtName = (TextView) convertView.findViewById(R.id.tv);
viewHolder.sk = (CrystalRangeSeekbar) convertView.findViewById(R.id.skr);
result=convertView;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
result=convertView;
}
lastPosition = position;
viewHolder.sk.setOnRangeSeekbarChangeListener(new OnRangeSeekbarChangeListener() {
@Override
public void valueChanged(Number minValue, Number maxValue) {
}
});
final String[] n = new String[1];
final long[] mn = new long[1];
final long[] mx = new long[1];
viewHolder.sk.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() {
@Override
public void finalValue(Number minValue, Number maxValue) {
n[0] = (String) viewHolder.txtName.getText();
mn[0] = (long) viewHolder.sk.getSelectedMinValue()/1000;
mx[0] = (long) viewHolder.sk.getSelectedMaxValue()/1000;
data.setMaxvalue(mx[0]);
data.setMinvalue(mn[0]);
data.setNam(n[0]);
dataSet.set(position,data);
}
});
viewHolder.txtName.setText(dataSet.get(position).getName());
viewHolder.sk.setMinValue(dataSet.get(position).getMin());
viewHolder.sk.setMaxValue(dataSet.get(position).getMax());
// Return the completed view to render on screen
return convertView;
}
数据模型:
public class TextDetails implements Serializable {
String name;
long minvalue;
long maxvalue;
public TextDetails(String name, long minvalue, long maxvalue ) {
this.name=name;
this.minvalue=minvalue;
this.maxvalue=maxvalue;
}
public String getName() {
return name;
}
public long getMin() {
return minvalue;
}
public long getMax() {
return maxvalue;
}
public void setNam(String name) {
this.name=name;
}
public void setMinvalue(long minvalue) {
this.minvalue=minvalue;
}
public void setMaxvalue(long maxvalue) {
this.maxvalue=maxvalue;
}
}