Seekbar is not getting properly updated in listview

53 views Asked by At

I have a list view with range seekbars and I am adding it for choosing the duration of the text overlay in the video. When I am adding multiple seekbars dynamically, only the last seekbar change is reflected properly in the arraylist,varying the value of other seekbars are not properly updated.

Adapter Code:

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

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