[안드로이드]프로그레스바,ProgressBar

2013. 1. 30. 13:01Mobile/Android



반응형

 

 

 

 

 

package com.example.ggari_progressbar;

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 {

	ProgressBar progressbar;

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

		progressbar = (ProgressBar) findViewById(R.id.progressbar);

		findViewById(R.id.btnStart).setOnClickListener(OnClick);
		findViewById(R.id.btnStop).setOnClickListener(OnClick);
	}

	Button.OnClickListener OnClick = new View.OnClickListener() {
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btnStart:
				progressbar.setVisibility(View.VISIBLE);
				break;
			case R.id.btnStop:
				progressbar.setVisibility(View.INVISIBLE);
				break;
			}
		}
	};

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btnStart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="시작" />

        <Button
            android:id="@+id/btnStop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="정지" />
    <LinearLayout>

</LINEARLAYOUT>
반응형