简体   繁体   中英

How to set progress bar in android?

I want set progress bar until the next activity start.That mean i want to remove black screen while loading next page or activity.How to solve this problem?

yes I'm using button onClick and using listView to move next activity.

Button b1 = new Button(this);
b1.setOnTouchListener(new OnTouchListener() 
            {
                public boolean onTouch(View v, MotionEvent event) 
                {
                    int action = event.getAction();
                     if(action==0)
                     {
                     }
                     else  if(action == 1)
                     {   
                        final ProgressDialog dialog = ProgressDialog.show(myFirstActivity.this,"Please wait","Loading...",true);
                         new Thread() 
                         {
                               public void run() 
                               {
                                    try 
                                    {
                                        Thread.sleep(2000);
                                    } catch (InterruptedException e) 
                                    {
                                        e.toString();
                                        e.printStackTrace();
                                    }
                                    finally
                                    {
                                        dialog.dismiss();           
                                    }
                               }
                         }.start();
                      } 
                    return false;
                }
            });



     b1.setOnClickListener(new OnClickListener()
                {
                    public void onClick(View v) 
                    {
                             Intent i1 = new Intent(myFirstActiviyt.this,Second.class);
                             startActivity(i1);
                             }
                             });

Try this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM