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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:13:47+00:00 2026-06-14T06:13:47+00:00

I am new to android ,I want make an app which needs a progress

  • 0

I am new to android ,I want make an app which needs a progress bar, but the code which I wrote seems to crash each time I run it .As till now I am unable to find the bug.I am using a vertical progress bar.

thanx in advance.

package com.example.progtask;

import android.app.Activity;

import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends Activity implements OnClickListener, Runnable {
    private ProgressBar pb;
    private Button show;
    private Button hide;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pb = (ProgressBar) findViewById(R.id.progressBar1);
        show = (Button) findViewById(R.id.button1);
        hide = (Button) findViewById(R.id.hide);
        // pb.setVisibility(ProgressBar.GONE);
        show.setOnClickListener(this);
        hide.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.equals(show)) {

            pb.setVisibility(ProgressBar.VISIBLE);
            pb.setProgress(0);
            pb.setMax(12);
            new Thread(this).start();
        } else {
            pb.setVisibility(ProgressBar.GONE);
        }

    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        int n = 0;
        while (n < 10) {
            n++;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        pb.setProgress(n);

    }

}

Below is the Xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        android:text="picelate"
        tools:context=".MainActivity" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="82dp"
        android:layout_toLeftOf="@+id/textView1"
        android:text="show" />

    <Button
        android:id="@+id/hide"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_toRightOf="@+id/textView1"
        android:text="hide" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_alignParentLeft="true" />

</RelativeLayout>
  • 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-14T06:13:48+00:00Added an answer on June 14, 2026 at 6:13 am

    This is how it worked:

     public class MainActivity extends Activity implements OnClickListener, Runnable {
    
        private ProgressBar pb;
        private Button show;
        private Button hide;
    int n;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            pb = (ProgressBar) findViewById(R.id.progressBar1);
            show = (Button) findViewById(R.id.button1);
            hide = (Button) findViewById(R.id.button2);
            // pb.setVisibility(ProgressBar.GONE);
            show.setOnClickListener(this);
            hide.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             switch (v.getId())
                {
                   case R.id.button1:
    
                    pb.setVisibility(ProgressBar.VISIBLE);
                    pb.setProgress(0);
                    pb.setMax(100);
                    n = 0;
                    new Thread(this).start();
                   break;
    
                  case R.id.button2:
                 // do the needful.
                      pb.setVisibility(ProgressBar.GONE);
                 break;
                }
        }
    
        @Override
        public void run() {
            // TODO Auto-generated method stub
            int n = 0;
            while (n < 100) {
                n++;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }pb.setProgress(n*10);
    
            }
            pb.setProgress(n*10);
    
        }
    
    
    }
    

    the xml file is:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
          <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="show" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
    
            android:text="hide" />
    
        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
          android:progressDrawable="@drawable/progbar"
          android:layout_gravity="bottom"
            />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new android app developer i want make app for tablets and phone
I want to make an android app which will update status in twitter. I
I am new to android.I want to make application which displays the map when
I want to make GPS app and I'm starting with this code which is
We are designing a new application for Android and we want to make it
I am a new android app developer and i want to use google map
I'm new in android and i'm trying to make an android app to display
Hi i'm new to android my client want to run the app in their
I want to make a simple calculator My code is below: package som.dev.android.calc; import
I want to make an android application which has two tap in one view

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.