Activityの切り替えをProgressDialogでバッファリングする

6913 ワード

まず、主なActivityセクションを見てみましょう.
package com.misoo.kx03;

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

public class ac01 extends Activity implements OnClickListener {

private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

private Button btn, btn2;

private ProgressDialog progressDialog = null;

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

LinearLayout layout = new LinearLayout(this);

layout.setOrientation(LinearLayout.VERTICAL);

btn = new Button(this);

btn.setText("load map");

btn.setOnClickListener(this);

layout.addView(btn, new LinearLayout.LayoutParams(WC, WC));

btn2 = new Button(this);

btn2.setText("Exit");btn2.setOnClickListener(this);

layout.addView(btn2, new LinearLayout.LayoutParams(WC, WC));

setContentView(layout);

}

public void onClick(View v){

if (v == btn){// 

progressDialog=ProgressDialog.show(this,"please wait…","Loading YourMap…",true); new Thread(){ public void run(){ try{ sleep(8000);// , ,  Intent intent = new Intent(); intent.setClass(ac01.this, DispActivity.class); startActivity(intent); } catch(Exception e) { e.printStackTrace(); } progressDialog.dismiss(); } }.start(); setTitle("this main thread");

}

if(v.equals(btn2)) this.finish();

}}

Activityのサブカテゴリの作成:DispActivity
package com.misoo.kx03;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.LinearLayout;

import android.widget.TextView;

public class DispActivity extends Activity implements OnClickListener {

private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

public static final int EXIT_ID = Menu.FIRST + 2;

private TextView tx;@Override public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setTitle("Second Screen");

tx = new TextView(this);

tx.setText("Here Is Your Map.");

setContentView(tx, new LinearLayout.LayoutParams(WC, WC));

}

@Override public boolean onCreateOptionsMenu(Menu menu) {

super.onCreateOptionsMenu(menu);

menu.add(0, EXIT_ID, 0, "Exit");

return true;

}

public void onClick(View v)

{ setTitle("yes"); }

@Override public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

case EXIT_ID:

this.finish();

return true;

}

return super.onOptionsItemSelected(item);

}}