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

  • SEARCH
  • Home
  • 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

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
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 am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.