Implement process circle in Android

In this article, we are going to learn about process circle to show user process waiting time and the method to implement it in Android.
Submitted by Manu Jemini, on February 08, 2018

In the example below, we are going to use the ProgressBar class to show the user that the app is loading something and the user should wait.

To implement this in your program you will need to import in java file: android.widget.ProgressBar

Then create a layout file with a single EditText and Button like this:

<Button
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="Click here to show process circle"
	android:id="@+id/button"
	android:layout_centerHorizontal="true"
	android:onClick="show"/>

<ProgressBar
	style="?android:attr/progressBarStyleLarge"
	android:layout_width="350dp"
	android:layout_height="wrap_content"
	android:id="@+id/process_circle"
	android:progressDrawable="@drawable/process_circle"
	android:layout_below="@+id/button"
	android:layout_alignParentBottom="true"
	android:layout_alignParentEnd="true" />

In the Button above, we have put an onClick property and set it to show function which is in the java File.

First we will take the reference of the ProgressBar and Button from the layout file, set the visibility of the ProgressBar as Gone, this will make the Bar vanish from the screen and it will not take any space.

C.setVisibility(View.GONE);

Then whenever a user clicks the button we set the visibility of the ProgressBar as Visible, so it comes back on the screen.

C.setVisibility(View.VISIBLE);

1) Java file:

package com.example.hp.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity{
	ProgressBar C;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		C=(ProgressBar)findViewById(R.id.process_circle);
		C.setVisibility(View.GONE);
	}
	
	public void show(View v){
		C.setVisibility(View.VISIBLE);
	}
}

2) XML file:

<?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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.myapplication.MainActivity">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click here to show process circle"
        android:id="@+id/button"
        android:layout_centerHorizontal="true"
        android:onClick="show"/>

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:id="@+id/process_circle"
        android:progressDrawable="@drawable/process_circle"
        android:layout_below="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

3) Manifest file:

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Output

Implement process circle in Android 1
Implement process circle in Android 2

Implement process circle in Android 3


Related Tutorials



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.