How to Load an Activity using Progressbar

Asked

Viewed 621 times

0

Progressibar Code in XML

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <ProgressBar
    android:layout_height="11px"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="300px"
    android:id="@+id/load"
    android:layout_centerInParent="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="52px"/>

</RelativeLayout>

Code of Progressbar in Java

package game.app;

import android.app.*;
import android.os.*;

public  class LoadActivity extends  Activity {

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.loadlayout);
  }
}

Activity that Progressbar will load

package game.app;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
import android.view.View.*;
import android.content.*;

public class MenuActivity extends Activity {

  private Button btiniciar;

  @Override

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menulayout);

    btiniciar = (Button) findViewById(R.id.btiniciar);
    btiniciar.setOnClickListener(new View.OnClickListener(){
      public void onClick(View v) {

        @Override

        Intent it = new Intent(MenuActivity.this,LoadActivity.class);
        startActivity(it);
        finish();
      }
    });

    Button btconfig = (Button) findViewById(R.id.btconfig);
    btconfig.setOnClickListener(new View.OnClickListener(){
      public void onClick(View argO) {


      }
    });
  }
}
  • For me it was not clear what you want to do. Just pasted the codes here

1 answer

0


Progressbar is an element of the user interface that indicates the progress of an operation, in this action you are doing there is no action that needs Progressbar.

An example where you can use Progressbar is the use of Asynctasks to load API data, download image and so on... unless to simulate the Progress you use some postDelayed setting a time to simulate a delay in the screen transition.

 btiniciar = (Button) findViewById(R.id.btiniciar);
    btiniciar.setOnClickListener(new View.OnClickListener(){
      public void onClick(View v) {

                //MOSTRAR PROGRESS
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                     //ESCONDER PROGRESS
                       Intent it = new Intent(MenuActivity.this,LoadActivity.class);
                       startActivity(it);
                       finish();
                    }
                }, 2000);
      }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.