首页 > 代码库 > Android显示“正在加载,请稍后...”

Android显示“正在加载,请稍后...”

如何实现点击按钮,弹出“正在加载数据,请稍候...”对话框,加载完了之后,对话框自动消失呢?

其实也是很简单的看下面代码:

<pre name="code" class="java">import java.util.List;

import com.farsunset.ichat.example.R;
import com.farsunset.ichat.example.adapter.DynamicListAdapter;
import com.farsunset.ichat.example.app.BaseInfo;
import com.farsunset.ichat.example.app.Dynamic;
import com.farsunset.ichat.example.app.Project;

import android.os.Bundle;
import android.os.Handler;
import android.widget.ListView;
import android.app.Activity;
import android.app.ProgressDialog;


public class DateReportActivity extends Activity {

	private ProgressDialog progressDialog;
	private ListView date_list;
	private Project project;

	private Handler handler = new Handler() {

		public void handleMessage(android.os.Message msg) {
			hideProgressDialog();
			
		}

	};

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

		
	}

	/*
	 * 提示加载
	 */
	public void showProgressDialog(String title, String message) {
		if (progressDialog == null) {

			progressDialog = ProgressDialog.show(DateReportActivity.this,
					title, message, true, false);
		} else if (progressDialog.isShowing()) {
			progressDialog.setTitle(title);
			progressDialog.setMessage(message);
		}

		progressDialog.show();

	}

	/*
	 * 隐藏提示加载
	 */
	public void hideProgressDialog() {

		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
		}

	}

}


至于XML文件写什么就不用管了,只要你在做项目的时候用到联网程序,就可以用以上的两个方法了

Android显示“正在加载,请稍后...”