activity_main.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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" 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="iterator.ir.a028.MainActivity"> <SeekBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="21dp" android:id="@+id/seekBar" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <TextView android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/seekBar" android:layout_centerHorizontal="true" android:layout_marginTop="42dp" android:id="@+id/textView" /> </RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity { SeekBar seekBar; TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView= (TextView) findViewById(R.id.textView); seekBar= (SeekBar) findViewById(R.id.seekBar); textView.setText(0 + " / " + seekBar.getMax()); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { textView.setText(progress + " / " + seekBar.getMax()); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } }
References
https://github.com/mhdr/AndroidSamples/tree/master/028