mainActivity.java - code of SeekBar
package com.example.raghukm.seek;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
SeekBar skbar;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=(TextView)findViewById(R.id.textView);
skbar=(SeekBar)findViewById(R.id.seekBar);
skbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar skBar, int i, boolean b) {
textView.setText("The Value of SeekBar is: "+i);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(),"SeekBar tracking Start",Toast.LENGTH_LONG).show();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(),"SeekBar tracking stop",Toast.LENGTH_SHORT).show();
}
});
}
}
activity_main.xml - code of SeekBar
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.raghukm.seek.MainActivity">
<SeekBar
android:id="@+id/seekBar"
android:layout_width="276dp"
android:layout_height="36dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="92dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteX="-62dp" />
<TextView
android:id="@+id/textView"
android:layout_width="336dp"
android:layout_height="132dp"
android:text="TextView"
android:textSize="30dp"
android:textAlignment="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="61dp"
app:layout_constraintTop_toBottomOf="@+id/seekBar"
app:layout_constraintHorizontal_bias="0.507" />
</android.support.constraint.ConstraintLayout>
SHARE THIS
0 Post a Comment: