Dialog里加入下拉框Java_Android入门第一篇之AlertDialog(多列显示的下拉列表框-Spinner)...

本文介绍如何在Android中创建AlertDialog,包括非阻塞对话框和基于布局的对话框。示例代码展示如何使用GridView实现多列下拉选择,并通过Adapter自定义视图。同时,讲解了AlertDialog的按钮监听和点击事件处理。
摘要由CSDN通过智能技术生成

本文来自http://blog.chinaunix.net/blog/post.html,引用必须注明出处!

231c2c2fe9942373f9418f95a257c8e6.png

这次要说的是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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值