Seekbar value is not getting updated in listview array adapter

153 views Asked by At

I have a range seekbar dynamically added to the list view and if I vary the range seekbar progress it's getting updated in the array adapter for last added item alone. If I vary previous items it's setting the min and max value as 0 and 0 in array adapter.

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

     View result=null;

    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);
        convertView.setTag(viewHolder);
        viewHolder.sk.setTag(dataSet.get(position));
        viewHolder.txtName.setTag(dataSet.get(position));
        result=convertView;

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
        result=convertView;
                   ((ViewHolder)result.getTag()).sk.setTag(dataSet.get(position));
        ((ViewHolder)result.getTag()).txtName.setTag(dataSet.get(position));
    }

    lastPosition = position;


    final String[] n = new String[1];
    final long[] mn = new long[1];
    final long[] mx = new long[1];

    final View finalConvertView = convertView;

    viewHolder.sk.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() {

        @Override
        public void finalValue(Number minValue, Number maxValue) {
            ViewHolder holder=(ViewHolder) finalConvertView.getTag();

            holder.txtName.setText(dataSet.get(position).getName());
            holder.sk.setMinValue(dataSet.get(position).getMin());
            holder.sk.setMaxValue(dataSet.get(position).getMax());

                TextDetails text =(TextDetails)viewHolder.sk.getTag();

            Log.e("Max and min value",""+minValue+maxValue +position);
            text.setMaxvalue((Long) maxValue/1000);
            text.setMinvalue((Long) minValue/1000);
            Log.e("Value",         String.valueOf(dataSet.get(position).getMax())+ "" + dataSet.get(position).getMin());
        }
    });

    ViewHolder holder=(ViewHolder)convertView.getTag();

    holder.txtName.setText(dataSet.get(position).getName());
    holder.sk.setMinValue(dataSet.get(position).getMin());
    holder.sk.setMaxValue(dataSet.get(position).getMax());
    // Return the completed view to render on screen
    return convertView;
}
}

DataModel

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;
}



}
0

There are 0 answers