activity_main.xml
<?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=".MainActivity">
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="fill_parent"
android:layout_height="127dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.272"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.115" />
<TextView
android:id="@+id/text_view"
android:layout_width="178dp"
android:layout_height="65dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.036"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.438" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.seekbarapps;
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 {
private static SeekBar seek_Bar;
private static TextView text_View;
private static int progress_val;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekbar();
}
public void seekbar(){
seek_Bar=(SeekBar)findViewById(R.id.seek_bar);
text_View=(TextView)findViewById(R.id.text_view);
text_View.setText("covered:="+seek_Bar.getProgress()+"/"+seek_Bar.getMax());
seek_Bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress_val;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_val=progress;
text_View.setText("covered:="+progress+"/"+seek_Bar.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) {
text_View.setText("covered:="+progress_val+"/"+seek_Bar.getMax());
Toast.makeText(MainActivity.this,"seekbar is stop tracking",Toast.LENGTH_LONG).show();
}
});
}
}
<?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=".MainActivity">
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="fill_parent"
android:layout_height="127dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.272"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.115" />
<TextView
android:id="@+id/text_view"
android:layout_width="178dp"
android:layout_height="65dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.036"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.438" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.seekbarapps;
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 {
private static SeekBar seek_Bar;
private static TextView text_View;
private static int progress_val;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekbar();
}
public void seekbar(){
seek_Bar=(SeekBar)findViewById(R.id.seek_bar);
text_View=(TextView)findViewById(R.id.text_view);
text_View.setText("covered:="+seek_Bar.getProgress()+"/"+seek_Bar.getMax());
seek_Bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress_val;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_val=progress;
text_View.setText("covered:="+progress+"/"+seek_Bar.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) {
text_View.setText("covered:="+progress_val+"/"+seek_Bar.getMax());
Toast.makeText(MainActivity.this,"seekbar is stop tracking",Toast.LENGTH_LONG).show();
}
});
}
}
0 comments:
Post a Comment