Android Studio Progress Dialog

Android Studio Progress Dialog

Android studio ‘da progress dialog’u görüceğiz. Öncelikle nedir bu ? Progress Dialog belirli bir işlem yaparken işlemin uzun sürmesine karşılık kullanıcılara sunduğumuz uyarı penceresidir. Mesela Dosya indirirken ki 100’e kadar dolma işlemi. Hadi bunu biz bir progress örneğinde yapalım

Activity_main , Layout Kodumuz : Sadece 1 tane button attık.

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<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:text="Progress Dialog Tıkla"

        android:layout_centerVertical="true"

        android:layout_centerHorizontal="true" />

 

</RelativeLayout>

Java Kodlarımız :

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

package com.umiitkose.egitim2;

 

import android.app.Activity;

import android.app.ProgressDialog;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

 

/**

* Android ProgressDialog example

* @author Prabu Dhanapal

* @version 1.0

* @since SEP 01 2013

*

*/

public class MainActivity extends Activity {

    Button button;

    ProgressDialog progressDoalog;

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener() {

            @Override

            public void onClick(View v) {

                progressDoalog = new ProgressDialog(MainActivity.this);

                progressDoalog.setMax(100);

                progressDoalog.setMessage("Yükleniyor...");

                progressDoalog.setTitle("Progres Dialog Örneği");

                progressDoalog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

                progressDoalog.show();

                new Thread(new Runnable() {

                    @Override

                    public void run() {

                        try {

                            while (progressDoalog.getProgress() <= progressDoalog

                                    .getMax()) {

                                Thread.sleep(200);

                                handle.sendMessage(handle.obtainMessage());

                                if (progressDoalog.getProgress() == progressDoalog

                                        .getMax()) {

                                    progressDoalog.dismiss();

                                }

                            }

                        } catch (Exception e) {

                            e.printStackTrace();

                        }

                    }

                }).start();

            }

 

            Handler handle = new Handler() {

                @Override

                public void handleMessage(Message msg) {

                    super.handleMessage(msg);

                    progressDoalog.incrementProgressBy(1);

                }

            };

        });

    }

 

 

}

 

 

 

Henüz Yorum Yapılmamış, İlk Yorumu Siz Yapın

Yorum Yollayın