Reputation: 83
I want my seekbar having values from 33 to 80, I have read in Google, that we cannot set minimum in xml, so I add 33 to progress. But the thing is that my seekbar gets values from 33 to 113(max + 30). Any tips will be valuable for me, thank you.
TextView textView123;
SeekBar seekBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc);
seekBar = (SeekBar) findViewById(R.id.seekBar1);
textView123 = (TextView) findViewById(R.id.progress);
textView123.setText(seekBar.getProgress() + " ");
seekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar,
int progresValue, boolean fromUser) {
progress = progresValue + 33;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do something here,
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
textView123.setText(progress + " ");
}
});
xml layout
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/backgroundpic" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp"
android:background="@color/white" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/seekBar1"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:text="Quantity"
android:textAppearance="?android:attr/textAppearanceLarge" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView4"
android:layout_marginTop="27dp"
android:max="80"
android:progress="1" />
<TextView
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="91dp"
android:text="33"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
Upvotes: 0
Views: 312
Reputation: 12919
Simple solution:
Set max to the actual value you want minus the min value you programmatically add in onProgressChanged
.
In your case, simply set max to 47 (80 - 33).
Upvotes: 1