smart guy
smart guy

Reputation: 23

How to show dummy progressbar for 2 second?

I just want to show progress bar before new activity starts. When I start activity from previous activity, the new screen first shows dummy progress bar (white screen with only progressbar) and after 2 or 3 second starts the new activity.

listCategory.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
        Intent iMenuList = new Intent(thirdstep.this,  fifthscreen.class);
        startActivity(iMenuList);
    }
});

public class fifthscreen extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fifthscreen);
    }
}

Upvotes: 0

Views: 3709

Answers (4)

Bhavna
Bhavna

Reputation: 856

You can place an imageView with width and height as fill_parent and change its background images frequently, that will give an illusion of a incrementing progress bar.

Inflate ur layout with another layout having imageView with width and height as fill_parent and a background image of progressBar showing initial value. Then use handlers..

new Handler().postDelayed(new Runnable() {

        @Override
        public void run() 
        {
            imageView.setBackgroundResource(R.drawable.progressImage2);

        }
    }, 3200);


new Handler().postDelayed(new Runnable() {

    @Override
    public void run() 
    {

        Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
        finish();
        startActivity(intent);
    }
}, 5000);

Upvotes: 0

user3513843
user3513843

Reputation:

You can try it using handler as below:

listCategory.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1,
        int position, long arg3) {
//Display your progressBar here
Handler mHand  = new Handler();
    mHand.postDelayed(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            Intent iMenuList = new Intent(thirdstep.this,  fifthscreen.class);
            //Dismiss progressBar here
            startActivity(iMenuList);
        }
    }, 2000);   
    }
}
});

You need to put this code inside onItemClick method.

Upvotes: 1

Auto-Droid ツ
Auto-Droid ツ

Reputation: 1593

 private class log_in extends AsyncTask<String,Void,String>{
        ProgressDialog pDialog;
        int a=0;
       boolean value1;
        @Override
         protected void onPreExecute(){
            pDialog = new ProgressDialog(LoginActivity.this);
            pDialog.setMessage("Authenticating user...");
            pDialog.show();
         }
        @Override
        protected Boolean doInBackground(String... params) {
           if(a>300)
           {value1=true;}
           else{a++;
             value1=false;}
            return value1;
        }
        protected void onPostExecute(Boolean params){
            super.onPostExecute(params);
            pDialog.dismiss();
            if(params){
                Intent intent=new Intent(LoginActivity.this,menu.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                LoginActivity.this.startActivity(intent);
            }
           else{
               error.setText("Wrong password or username combination");
            }

        }

     }

just call new log_in().execute(); where you want to call your next activity

Upvotes: 0

Seraphim&#39;s
Seraphim&#39;s

Reputation: 12768

Ok If your problem is that the activity takes a lot of time to display maybe you want to inflate the xml after the activity is displayed.

Here are the steps:

  1. Load a simply Activity and display it on the screen
  2. Show a progress bar
  3. Inflate a Layout containing all components you need in the activity
  4. Manage other initializations
  5. Hide the progress bar

Upvotes: 0

Related Questions