ProgressDialog Example in Android
ScreenShots:
ScreenShots:
Strings.xml
<?xml version="1.0"
encoding="utf-8"?>
<resources>
<string name="app_name">Progress Dialog</string>
<string name="hello_world">Hello world!</string>
<string
name="display">Display Progress</string>
</resources>
Activity_main.xml
<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"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="38dp"
android:layout_marginTop="48dp"
android:text="@string/display" />
</RelativeLayout>
MainActivity.java
package com.swamys.progressdialog;
import android.os.Bundle;
import
android.app.Activity;
import
android.app.ProgressDialog;
import android.view.Menu;
import android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
public class MainActivity extends Activity {
Button
progress;
ProgressDialog
dialog;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress=(Button)findViewById(R.id.button1);
progress.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog=new
ProgressDialog(MainActivity.this);
dialog.setTitle("Downloading");
dialog.setMessage("Please
wait.....");
dialog.setCancelable(false);
dialog.show();
Thread
thread=new Thread()
{
public void run()
{
try
{
sleep(10000);
}
catch(InterruptedException
e)
{
e.printStackTrace();
}
finally
{
dialog.dismiss();
}
}
};
thread.start();
}
});
}
}
No comments:
Post a Comment