Android Loading Spinner

Android Loading Spinner

What Is Android Loading Spinner?

When You Use Any Android Application And Ask The Application To Do Something Like Deleting Folders, Copy Folders Etc, Then Application Shows A Message Like Deleting Folders, Within The Message It Shows A Progress Bar, Indicator Or Loading Spinner So This Spinner Is Actually Called Android Loading Spinner.

android loading spinner

You can show progress of an activity in android through android loading progress bar or android loading spinner. The progress bar will generally has two shapes. Android Loading bar/Android Progress Bar and Android Loading Spinner. On this section we will discuss android loading spinner. Learn Android AlertDialog.

Usage Of Android Loading Spinner

Android Loading Spinner can be used to display improvement of those responsibilities whose total time of conclusion is unknown. To be able to use that, you merely need to identify it in the xml such as this.

<ProgressBar
   android:id="@+id/progressBar1"
   style="?android:attr/progressBarStyleLarge"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_centerHorizontal="true" />

After determining it in xml, you need to get its research in java data file through ProgressBar class. Its syntax is listed below

private ProgressBar spinner;
spinner = (ProgressBar)findViewById(R.id.progressBar1);

Then you can make its disappear , and take it when needed through setVisibility Method. Its syntax is listed below

spinner.setVisibility(View.GONE);
spinner.setVisibility(View.VISIBLE);	

Apart from these procedures, there are other methods described in the ProgressBar, which you can use to take care of android loading spinner better.

Methods Of Android Loading Spinner

  1. isIndeterminate()
  2. postInvalidate()
  3. setIndeterminate(boolean indeterminate)
  4. invalidateDrawable(Drawable dr)
  5. incrementSecondaryProgressBy(int diff)
  6. getProgressDrawable()

Android Loading Spinner Example

Here is a good android loading spinner example demonstrating the utilization of ProgressBar to take care of android loading spinner. It generates a basic request which allows you to carefully turn on the spinner on clicking on the button.

To test out this android loading example , you can run this on a genuine device or within an emulator.

Steps     Description

  1. You use Android studio to generate an Android software under a package com.example.androdevelopment.myapplication.
  2. Modify src/MainActivity.java to include necessary code.
  3. Modify the res/structure/activity_main to include particular XML components
  4. Need to make a xml record in drawable folder.it includes condition and rotate information about the progress bar
  5. Run the application form and choose a running google android device and set up the application onto it and validate the results

Content -> Modified src/MainActivity.java (What Is Main Activity File)

package com.example.androdevelopment.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;


public class MainActivity extends Activity {
   Button b1;

   private ProgressBar spinner;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
        
      b1=(Button)findViewById(R.id.button);
      spinner=(ProgressBar)findViewById(R.id.progressBar);
      spinner.setVisibility(View.GONE);

      b1.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            spinner.setVisibility(View.VISIBLE);
         }
      });
   }
}

 

Content ->res/layout/activity_main.xml(What Is MainActivity File)

Here abc shows logo of Andro Development.


Do You Have Any Question About This Tutorial? Ask Question Now On Andro Development & Get Answer Instantly. No Signup/Login Needed


<?xml version="1.0" encoding="utf-8"?>
<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" 
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
   
   <TextView android:text="Progress Dialog" android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textview"
      android:textSize="35dp"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" />
      
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Andro Development"
      android:id="@+id/textView"
      android:layout_below="@+id/textview"
      android:layout_centerHorizontal="true"
      android:textColor="#ff7aff24"
      android:textSize="35dp" />
      
   <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="download"
      android:id="@+id/button"
      android:layout_below="@+id/imageView"
      android:layout_centerHorizontal="true" />
      
   <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:src="@drawable/abc"
      android:layout_below="@+id/textView"
      android:layout_centerHorizontal="true" />
      
   <ProgressBar
      style="?android:attr/progressBarStyleLarge"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/progressBar"
      android:progressDrawable="@drawable/circular_progress_bar"
      android:layout_below="@+id/button"
      android:layout_alignRight="@+id/textView"
      android:layout_alignEnd="@+id/textView"
      android:layout_alignLeft="@+id/textview"
      android:layout_alignStart="@+id/textview"
      android:layout_alignParentBottom="true" />

</RelativeLayout>

Content ->  res/drawable/circular_progress_bar.xml.

<?xml version="1.0" encoding="utf-8"?>
<rotate
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:fromDegrees="90"
   android:pivotX="50%"
   android:pivotY="50%"
   android:toDegrees="360">
   
   <shape
      android:innerRadiusRatio="3"
      android:shape="ring"
      android:thicknessRatio="7.0">
      
      <gradient
         android:centerColor="#007DD6"
         android:endColor="#007DD6"
         android:startColor="#007DD6"
         android:angle="0"
         android:type="sweep"
         android:useLevel="false" />
   </shape>
   
</rotate>

 

Content -> AndroidManifest.xml (What Is AndroidManifest File)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.androdevelopment.myapplication" >

   <application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      
      <activity
         android:name="com.example.androdevelopment.myapplication.MainActivity"
         android:label="@string/app_name" >
         
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
         
      </activity>
      
   </application>
</manifest>

Let’s make an effort to run our android loading spinner app we just customized. I assume you’d created your AVD while doing Android Environment Setup. To perform the app from Android studio room, open up one of your project’s activity data files and click Run Eclipse Run icon from the toolbar. Google android studio room installs the app on your AVD and begins it of course, if everything is okay with your installation and application, it’ll display pursuing Emulator window

android loading spinner

Now go through the load spinner button to carefully turn on the loading spinner. It really is shown in

android loading spinner

Here Our Tutorial Ends 🙂

See Also:

Learn About Manifest And Main Activity File

Android AlertDialog

Android Animations

 

 


Do You Have Any Question About This Tutorial? Ask Question Now On Andro Development & Get Answer Instantly. No Signup/Login Needed