I have a simple question. I have a list of SeekBar
. My requirement is when the user drags the first SeekBar
to 70% the next one should stop at 30%. How can I stop SeekBar
progress to a specific value or % in my case?
public class ProductsAdapter extends BaseAdapter {
private ArrayList<Products> list;
//private LayoutInflater layoutInflater;
private int shelfShareSum;
private int remainingShelfShare;
private static HashMap<String, Integer> shelfShareValues = new HashMap<String, Integer>();
private HashMap<Integer, Integer> productShelfShareMap = new HashMap<Integer, Integer>();
private Context con;
private SQLiteDatabase database;
private SQLiteOpenHelper dbHelper;
//SparseIntArray seekbarValuePos = new SparseIntArray();
public ProductsAdapter(Context context, ArrayList<Products> list){
this.list = list;
//layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
dbHelper = new DBHelper(context);
database = dbHelper.getWritableDatabase();
this.con = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
final shelfShareHolder holder;
if (row == null){
LayoutInflater mInflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = mInflater.inflate(R.layout.shelf_share_list_view, null);
holder = new shelfShareHolder();
holder.productTextView = (TextView) row.findViewById(R.id.shelfShareProductTextView);
holder.percentTextView = (TextView) row.findViewById(R.id.seekbarValue);
holder.shelfShareSeekbar = (SeekBar) row.findViewById(R.id.seekBar1);
row.setTag(holder);
}else {
holder = (shelfShareHolder) row.getTag();
}
Products p = list.get(position);
//int pID = p.getProductID();
int prog = p.getSetSlider();
holder.shelfShareSeekbar.setProgress(list.get(position).getSetSlider());
holder.shelfShareSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//shelfShareSum = progress;
holder.percentTextView.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
remainingShelfShare = 100 - shelfShareSum;
Integer preV = productShelfShareMap.get(((Products)list.get(position)).getProductID());
if(preV == null){
holder.shelfShareSeekbar.setMax(remainingShelfShare);
}else {
holder.shelfShareSeekbar.setMax(Integer.parseInt(holder.percentTextView.getText().toString()) + remainingShelfShare);
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*shelfShareSum +=Integer.parseInt(seekBarValue.getText().toString());
Log.i("SUM", "onStopTrackingTouch: "+shelfShareSum);
seekBar.setMax(shelfShareSum);*/
list.get(position).setSetSlider(seekBar.getProgress());
shelfShareSum = 0;
//remainingShelfShare = 100;
productShelfShareMap.put(((Products)list.get(position)).getProductID(), Integer.parseInt(holder.percentTextView.getText().toString()));
for (HashMap.Entry<Integer, Integer> entry : productShelfShareMap.entrySet()){
shelfShareSum += entry.getValue();
}
shelfShareValues.put(((Products)list.get(position)).getShelfShareID()+"-"+((Products)list.get(position)).getProductID(), Integer.parseInt(holder.percentTextView.getText().toString()));
//shelfShareValues.put(((Products)list.get(position)).getShelfShareID()+"-"+((Products)list.get(position)).getCategoryID(), Integer.parseInt(holder.percentTextView.getText().toString())+"-"+((Products)list.get(position)).getProductID());
//Info.getInstance().setShelfSharePercent(shelfShareValues);
}
});
holder.productTextView.setText(((Products)list.get(position)).getProductName());
return row;
}
public static HashMap<String, Integer> sendshelfShareValuesMap(){
return shelfShareValues;
}
private static class shelfShareHolder{
TextView productTextView;
SeekBar shelfShareSeekbar;
TextView percentTextView;
}
}