Reputation: 598
Above the generateData() method, i declared an integer variable bw, i want it to be equal to the value of the current seekbar progress, how to do that? or actually can i directly use the value of progress for calculation?? Sorry it may sound a stupid question but i am absolute new to programming.
If I put bw=progress; inside the onprogresschanged, the outcome of bw*10 and bw*9 will become 0 no matter how i slide the seekbar.
public class MainActivity extends AppCompatActivity {
int bw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyAdapter adapter = new MyAdapter(this, generateData());
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
final TextView seekBarValue = (TextView) findViewById(R.id.valuetextview);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
bw=progress;
seekBarValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
//Detail of drugs in following formatL "Drug Name", doseperkg,"frequency"
private ArrayList<DrugItem> generateData() {
ArrayList<DrugItem> items = new ArrayList<DrugItem>();
items.add(new DrugItem("Ceclor", bw * 10, "mg every 8 hours"));
items.add(new DrugItem("Cedax", bw * 9, "mg every 24 hours"));
items.add(new DrugItem("Zinnat", bw * 10, "mg every 12 hours"));
items.add(new DrugItem("Zithromax", bw * 10, "mg every 24 hours"));
return items;
}
}
Upvotes: 1
Views: 2066
Reputation: 4522
in the callback methods of seekbar
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
bw=progress;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
in addition to that you may want to set a maximum value to seekbar's seek
seekBar.setMax(max_value-min_value);
Upvotes: 0
Reputation: 2970
yes obvious.
In below method int progress this is your main point value. U can use it for calculation .
but make sure work around in onProgressChanged method.
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// your calculation...
}
Upvotes: 2