Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5992561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:32:58+00:00 2026-05-22T23:32:58+00:00

I’m trying to move the position of the seekbar using a button. Basically I

  • 0

I’m trying to move the position of the seekbar using a button. Basically I have a seekbar from 0 to 100. and I have button presents set up at arbitrary values (40,50,60 etc). When I try to set the progress on the seekbar via button, I get a fault.. I’ve already initialized the seekBar in the onCreate() method.

    SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar1);
    currentProgress = 40;
    seekBar.setMax(100);
    seekBar.setProgress(currentProgress);
    button40.setOnClickListener(button40Listener);

But when use the below, it crashes.

    private OnClickListener button40Listener = new OnClickListener() {
        public void onClick(View v) {
          currentProgress = 40;
          seekBar.setProgress(currentProgress);
        }
    }

This seems straight-forward. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:32:59+00:00Added an answer on May 22, 2026 at 11:32 pm

    You shouldn’t need to put up another Seekbar. The initial one should be fine. Without the exception message and stack trace I’m not sure what is causing the crash. However, I just coded an example and works as you would expect. Perhaps by looking at my example you can identify your issue.

    SeekbarTest.java:

    package com.example.seekbartest;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.SeekBar;
    
    public class SeekbarTest extends Activity {
    /** Called when the activity is first created. */
    private SeekBar seekBar;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        seekBar = (SeekBar)findViewById(R.id.seekBar1);
    
        Button fortyPctButton = (Button)findViewById(R.id.buttonFortyPct);
        fortyPctButton.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                seekBar.setProgress(40);
            }
        });
    
        Button sixtyPctButton = (Button)findViewById(R.id.buttonSixtyPct);
        sixtyPctButton.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                seekBar.setProgress(60);
            }
        });
    
        Button eightyPctButton = (Button)findViewById(R.id.buttonEightyPct);
        eightyPctButton.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                seekBar.setProgress(80);
            }
        });
        }
    }
    

    And here is the main.xml it is referencing for the layout:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
    <TextView 
        android:layout_width="fill_parent" 
        android:text="@string/hello"
        android:id="@+id/textView1" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true"/>
    
    <SeekBar 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/seekBar1" 
        android:layout_below="@+id/textView1" 
        android:layout_alignLeft="@+id/textView1" 
        android:layout_alignRight="@+id/textView1"/>
    
    <Button 
        android:layout_width="wrap_content" 
        android:text="40%" 
        android:id="@+id/buttonFortyPct" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/seekBar1"
        android:layout_alignLeft="@+id/seekBar1"/>
    
    <Button 
        android:layout_width="wrap_content" 
        android:text="60%" 
        android:id="@+id/buttonSixtyPct" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/buttonFortyPct" 
        android:layout_alignTop="@+id/buttonFortyPct" 
        android:layout_alignBottom="@+id/buttonFortyPct"/>
    
    <Button 
        android:layout_width="wrap_content" 
        android:text="80%" 
        android:id="@+id/buttonEightyPct" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/buttonSixtyPct" 
        android:layout_alignTop="@+id/buttonSixtyPct" 
        android:layout_alignBottom="@+id/buttonSixtyPct"/>
    </RelativeLayout>
    

    Just create a new android app and replace the generated code + layout with the example above. It should work for you.

    Good luck,
    Craig

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.