One normal UI highlight in an Android gadget is the "Please wait" exchange that you ordinarily observe when an application is playing out a long-running errand. For instance, the application may be signing in to a worker before the client is permitted to utilize it, or it very well may be doing a computation prior to showing the outcome to the client. In such cases, it is useful to show a discourse, known as a progress dialog, with the goal that the client is kept on top of it.
Displaying a Progress Dialog (Please Wait):-
1.Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.jfdimarzio.activity101">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Material">
<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>
2.MainActivity.java file:
package com.android.activity101;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.CountDownTimer;
import android.os.Bundle;
public class MainActivity extends Activity {
ProgressDialog progressDialog;
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}
public void onStart()
{
super.onStart();
progressDialog = ProgressDialog.show(this,"Please Wait", "Processing...",true);
CountDownTimer timer = new CountDownTimer(3000,1000)
{
@Override
public void onTick(long millisUntilFinished)
{
}
@Override
public void onFinish()
{
progressDialog.dismiss();
}
}.start();
}
3.Press Shift+F9 to investigate the application on the Android emulator. You see the improvement exchange. It vanishes following three seconds.
How It Works
To make an progress dialog, you make an example of the ProgressDialog class and call its show()method:
progressDialog = ProgressDialog.show(this,"Please Wait", "Processing...",true);
This shows the advancement exchange. Since this is a modular exchange, it will impede the UI until it is excused. To close the exchange, you make a clock that calls the excuse() technique following three seconds.
CountDownTimer timer = new CountDownTimer(3000,1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
progressDialog.dismiss();
}
}.start();
After the three seconds have slipped by, you excuse the discourse by calling the excuse() technique.
The following segment clarifies utilizing Intents, which assist you with exploring different Activities.
Comments
Post a Comment