本文来自http://blog.chinaunix.net/blog/post.html,引用必须注明出处!
这次要说的是AlertDialog,这种对话框会经常遇到。AlertDialog是非阻塞的,而阻塞的对话框用的是PopupWindow。
先贴出程序运行的截图:
主Activity
MainActivity.java
package com.example.testandroid;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;
//下拉
public class MainActivity extends Activity {
LinearLayout layout;
//Builder builder;
GridView gridView;
private MyAdapter adapter;
private AlertDialog dialog;
private int index = 0;
TextView textView;
Button btnShowDialog;
Button btnShowDialog_Layout;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new MyAdapter(this);
setContentView(R.layout.activity_main);
LayoutInflater inflater = LayoutInflater.from(this);
layout = (LinearLayout) inflater.inflate(R.layout.bank_grid, null);
gridView = (GridView) layout.findViewById(R.id.grid);
gridView.setAdapter(adapter);
btnShowDialog=(Button)this.findViewById(R.id.Button01);
btnShowDialog_Layout=(Button)this.findViewById(R.id.Button02);
textView = (TextView) find