Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should have read the documentation before asking such a generic question. Indeed, I would like to answer to this question in layman terms. Just think about seekbar as a simple sensor. It can fire events like onProgressChanged(). Means, the interface for seekbar can tell us when the seekbar progress is changed. Thus, we can do some operations inside the callbacks provided by Android. So take a look at the code and see this is what you are looking for. This is a test application I have created for this question.</p> <pre><code>public class SeekbarActivity extends Activity implements SeekBar.OnSeekBarChangeListener { private SeekBar seekbar; private TextView value; private Button plus,minus; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); value = (TextView) findViewById(R.id.value); seekbar = (SeekBar) findViewById(R.id.seekbar); plus = (Button) findViewById(R.id.plus); minus = (Button) findViewById(R.id.minus); seekbar.setOnSeekBarChangeListener(this); seekbar.setMax(201); plus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {seekbar.setProgress((int)seekbar.getProgress() + 1);}}); minus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {seekbar.setProgress((int)seekbar.getProgress() - 1);}}); } @Override public void onProgressChanged(SeekBar arg0, int progress, boolean fromTouch) { value.setText(String.valueOf(progress)); } @Override public void onStartTrackingTouch(SeekBar arg0) {} @Override public void onStopTrackingTouch(SeekBar arg0) {} } </code></pre> <p>And this is the XML used for this application</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/value" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Progress" /&gt; &lt;SeekBar android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" /&gt; &lt;Button android:id="@+id/plus" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="+" /&gt; &lt;Button android:id="@+id/minus" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="-" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Feel free to ask if you have any doubt on this code. By the way, this is not a code generating forum! Seems like I'm breaking one of the SOF terms... :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload