Android¥¢¥×¥ê¤ò³«È¯¤¹¤ë¤¿¤á¤Î´ðÁäò¤Þ¤È¤á¤Æ¤¢¤ê¤Þ¤¹¡£

Step1

¼¡¤Î¥×¥í¥¸¥§¥¯¥È¤òºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡£
¹àÌÜ̾ÀßÄêÃÍ
¥×¥í¥¸¥§¥¯¥È̾12th_practice_1
¥Ó¥ë¥É¥¿¡¼¥²¥Ã¥ÈAndroid 2.2
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó̾¥×¥í¥°¥ì¥¹¥Ð¡¼
¥Ñ¥Ã¥±¡¼¥¸Ì¾jp.co.example.practice
¥¢¥¯¥Æ¥£¥Ó¥Æ¥£¤ÎºîÀ®MainActivity
ºÇ¾®SDK¥Ð¡¼¥¸¥ç¥ó8

Step2

res/layout/main.xml¤ò¡¢¼¡¤ÎÆâÍƤËÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button 
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dip"
        android:text="Toast¤òɽ¼¨" />
    <Button 
        android:id="@+id/buttonDialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dip"
        android:text="Dialog¤òɽ¼¨" />
    <ProgressBar
        android:id="@+id/ProgressBarSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        style="?android:attr/progressBarStyleSmall" />
    <ProgressBar
        android:id="@+id/ProgressBarNormal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        style="?android:attr/progressBarStyle" />
    <ProgressBar
        android:id="@+id/ProgressBarLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        style="?android:attr/progressBarStyleLarge" />
    <ProgressBar
        android:id="@+id/ProgressBarHorizonInd"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dip"
        style="?android:attr/progressBarStyleHorizontal" />
    <ProgressBar
        android:id="@+id/ProgressBarHorizon"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dip"
        style="?android:attr/progressBarStyleHorizontal" />
</LinearLayout>

Step3

src/jp.co.example.practice/MainActivity.javan¤ÎonCreate()¥á¥½¥Ã¥É¤ÎÆâÍƤò¡¢Êѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£
@Override
public class MainActivity extends Activity {
	private ProgressBar progressbarHorizon;
	private ProgressBar progressbarHorizonInd;
	private Button button;
	private Button buttonDialog;
	private int progressStatus;

public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.progressbar);

	progressbarHorizon = (ProgressBar) findViewById(R.id.ProgressBarHorizon);
	progressbarHorizonInd = (ProgressBar) findViewById(R.id.ProgressBarHorizonInd);
	progressbarHorizonInd.setIndeterminate(true);

	button = (Button) findViewById(R.id.button);
	button.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast.makeText(ProgressBarTaskActivity.this, "¥È¡¼¥¹¥È¤òɽ¼¨",
					Toast.LENGTH_SHORT).show();
		}
	});
	buttonDialog = (Button) findViewById(R.id.buttonDialog);
	buttonDialog.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			new AlertDialog.Builder(ProgressBarTaskActivity.this)
					.setTitle("AlertDialog!")
					.setPositiveButton("Yes",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
								}
							})
					.setNegativeButton("No",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
								}
							}).show();
		}
	});
}

Step4

src/jp.co.example.practice/MainActivity.javan¤Ë¡¢MyAsyncTask¥¯¥é¥¹¤òÄɲ䷤Ƥ¯¤À¤µ¤¤¡£
class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
	final String TAG = "MyAsyncTask";

	@Override
	protected void onPreExecute() {
		Log.d(TAG, "onPreExecute");
		progressStatus = 0;
	}

	@Override
	protected Void doInBackground(Void... params) {
		Log.d(TAG, "doInBackground");
		while (true) {
			if (progressStatus >= 100) {
				progressStatus = 0;
			}
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			// ¥×¥í¥°¥ì¥¹¥¹¥Æ¡¼¥¿¥¹¤Ë°ìÄêÃͤò²Ã»»
			progressStatus += 5;
			// ¥×¥í¥°¥ì¥¹¥¹¥Æ¡¼¥¿¥¹¤òÈ¿±Ç
			publishProgress(progressStatus);
		}
	}

	@Override
	protected void onProgressUpdate(Integer... values) {
		Log.d(TAG, "onProgressUpdate - " + values[0]);
		progressbarHorizon.setProgress(values[0]);
	}

	@Override
	protected void onPostExecute(Void result) {
		Log.d(TAG, "onPostExecute - " + result);
	}
}

Step5

src/jp.co.example.practice/MainActivity.javan¤Ë¡¢MyAsyncTask¤Î¼Â¹Ô½èÍý¤òÄɲ䷤Ƥ¯¤À¤µ¤¤¡£
public void onCreate(Bundle savedInstanceState) {
	
	// ------ Ãæά  ------

	buttonDialog.setOnClickListener(new OnClickListener() {
¡¡¡¡¡¡¡¡¡¡¡¡// ------ Ãæά  ------
	});
	
	// ¤³¤Î½èÍý¤òÄɲÃ
	new MyAsyncTask().execute();
}

Step6

¼Â¹Ô¤·¡¢°Ê²¼¤Î¤è¤¦¤Ëɽ¼¨¤µ¤ì¤Þ¤·¤¿¤«¡©
¡Ö¥È¡¼¥¹¥È¤òɽ¼¨¡×¡¦¡ÖDialog¤òɽ¼¨¡×¥Ü¥¿¥ó¤ò²¡²¼¤·¤Æ¤â¡¢¥×¥í¥°¥ì¥¹¥Ð¡¼¤¬¹¹¿·¤µ¤ì³¤±¤ë¤³¤È¤òǧ¤·¤Æ¤¯¤À¤µ¤¤¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹