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 8163849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:09:31+00:00 2026-06-06T19:09:31+00:00

What I have is a seekbar which is controlled by buttons rather than a

  • 0

What I have is a seekbar which is controlled by buttons rather than a slider using set/get progress.

I’m trying to get the seekbar progress to increase when a user presses a button and then stop increasing when they lift off the button. I have an onkey listener the detects up and down. I’m just not sure where to put the setprogress part, if I put a loop in on ACTION_DOWN, it’s then looping rather than detecting ACTION_UP the same seems to happen if I have a while loop for ACTION_DOWN.

I think I may also have to set refreshDraweableState, but I’ve not had much look with that either.

Potentially i’m trying to mess with seekbars too much but I’d appreciate any help/advice. Thanks!

This is my keylistner which is where I have been mostly messing about.

public boolean onKey(View view, int keyCode, KeyEvent event) {
    builder.setLength(0);
    switch (event.getAction()){
        case KeyEvent.ACTION_DOWN:
            builder.append(event.getKeyCode());
            String text = builder.toString();
            Log.w("seekbar", text);
            textView.setText(text);
            while (sk.getProgress() < 100){
                sk.setProgress(sk.getProgress()+1);
                sk.refreshDrawableState();
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    break;
                }
            }
            break;
        case KeyEvent.ACTION_UP:
            break;
    }
    return true;
}

}

  • 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-06-06T19:09:34+00:00Added an answer on June 6, 2026 at 7:09 pm

    You need to be able to stop your while loop in the ACTION_DOWN even, otherwise it will just keep going until it reaches 99.

    Also your while loop blocks the UI thread so I would put it in a new thread (not sure how to do that on plain Android, I use Mono for Android), and either stop that thread when the ACTION_UP event occurs, or put another check in your while loop that breaks it.

    In Mono for Android that would be done somewhat like this:

    public bool OnKey(View view, int keyCode, KeyEvent e)
    {
        switch(e.Action)
        {
            case KeyEventAction.Down:
                Start();
            break;
            case KeyEventAction.Up:
                Stop();
            break;
        }
    }
    
    private volatile bool _shouldStop;
    
    public void IncreaseProgress()
    {
        while (!_shouldStop && sk.Progress < 100)
        {
            //Working
            RunOnUiThread(() => {
                sk.Progress = sk.Progress+1;
                sk.RefreshDrawableState();
            });
            Thread.Sleep(50);
        }
        //Terminating
    }
    
    public void Start()
    {
        _shouldStop = false;
        Thread workerThread = new Thread(IncreaseProgress);
        workerThread.Start();
    }
    
    public void Stop()
    {
        _shouldStop = true;
        workerThread.Stop();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a Player view with seekbar and play/pause/rewind, etc. buttons, which are
So in my application, I have a seekbar that allows the user to set
I have a ClassCastException being thrown saying that I'm trying to cast a SeekBar
I have a ListView in which each item has a SeekBar. When I update
I have a problem with programmatically setting the progress drawable of a SeekBar. When
For example, I have write GUI. I have a SeekBar, I change the progress
I'm trying to move the position of the seekbar using a button. Basically I
I have multiple SeekBars which the user can manipulate to change various values in
I am using the stock SeekBar component to navigate through a set of ViewPagers
I want to have a SeekBar with a thumb that appears as the user

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.