XML File
<SeekBar
android:id="@+id/sbfactor"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:max="5"
android:progressDrawable="@drawable/bar"
android:thumb="@drawable/button_slider" />
Java Code
SeekBar sbTestFactor= (SeekBar) findViewById(R.id.sbfactor);
sbTestFactor.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
public void onProgressChanged(SeekBar seekBar, int progresValue,
boolean fromUser) {
progress = progresValue;
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
rate1 = progress;
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.toast_layout));
TextView tv = ((TextView) layout.findViewById(R.id.toast_text_1));
tv.setTypeface(type_regular);
tv.setText("Your Rating Is " + progress);
Toast toast1 = new Toast(getBaseContext());
toast1.setDuration(Toast.LENGTH_SHORT);
toast1.setGravity(Gravity.TOP | Gravity.CENTER, 0, 400);
toast1.setView(layout);
toast1.show();
try {
//set result on textview
tvTestFactor.setText("" + rate1 + "/5");
} catch (Exception e) {
e.printStackTrace();
}
}
});
<SeekBar
android:id="@+id/sbfactor"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:max="5"
android:progressDrawable="@drawable/bar"
android:thumb="@drawable/button_slider" />
Java Code
SeekBar sbTestFactor= (SeekBar) findViewById(R.id.sbfactor);
sbTestFactor.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
public void onProgressChanged(SeekBar seekBar, int progresValue,
boolean fromUser) {
progress = progresValue;
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
rate1 = progress;
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.toast_layout));
TextView tv = ((TextView) layout.findViewById(R.id.toast_text_1));
tv.setTypeface(type_regular);
tv.setText("Your Rating Is " + progress);
Toast toast1 = new Toast(getBaseContext());
toast1.setDuration(Toast.LENGTH_SHORT);
toast1.setGravity(Gravity.TOP | Gravity.CENTER, 0, 400);
toast1.setView(layout);
toast1.show();
try {
//set result on textview
tvTestFactor.setText("" + rate1 + "/5");
} catch (Exception e) {
e.printStackTrace();
}
}
});
No comments:
Post a Comment