SeekBar Example

SeekBar Example in Android

MainActivity CLASS

package com.example.malik.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

SeekBar seekBar;
TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

onClickListeners();

}

private void onClickListeners() {
textView = (TextView) findViewById(R.id.textView);
seekBar = (SeekBar) findViewById(R.id.seekBar);

textView.setText(“Covered : ” + seekBar.getProgress() + ” / ” + seekBar.getMax());

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress_value;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_value = progress;
textView.setText(“Covered : ” + progress + ” / ” + seekBar.getMax());
Toast.makeText(MainActivity.this, “Seekbar in progress”, Toast.LENGTH_LONG).show();
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(MainActivity.this, “Seekbar in StartTracking”, Toast.LENGTH_LONG).show();
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
textView.setText(“Covered : ” + progress_value + ” / ” + seekBar.getMax());
Toast.makeText(MainActivity.this, “Seekbar in StopTrackingTouch”, Toast.LENGTH_LONG).show();
}
});
}
}

 

MainActivity XML

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.example.malik.test.MainActivity”>
<SeekBar
android:layout_width=”match_parent”
android:layout_height=”50dp”
android:id=”@+id/seekBar”
android:layout_alignParentTop=”true”
android:layout_alignParentRight=”true”
android:layout_alignParentEnd=”true”
android:layout_marginTop=”60dp” />

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textAppearance=”?android:attr/textAppearanceLarge”
android:text=”Large Text”
android:id=”@+id/textView”
android:layout_below=”@+id/seekBar”
android:layout_centerHorizontal=”true”
android:layout_marginTop=”60dp” />
</RelativeLayout>

 

OutPut:

pic

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.