`
大头K
  • 浏览: 183490 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论
阅读更多
先看看效果:



解释,在AlertDialog里添加一个listView,listitem在adapter里自定义,
贴关键代码:

AlertDialog:
				final String[] names = { "置顶", "删除" };// 列表中显示的内容组成的数组
				Builder builder = new AlertDialog.Builder(HomeActivity.this);  
                builder.setTitle("XXXXXX");  
                BaseAdapter adapter = new HomeLongClickAdapter(HomeActivity.this, names);  
                DialogInterface.OnClickListener listener =   
                    new DialogInterface.OnClickListener() {  
                        @Override  
                        public void onClick(DialogInterface dialogInterface, int which) {  
                             
                        }  
                    };  
                builder.setAdapter(adapter, listener);  
                builder.create();
                builder.show();



Adapter:
public class HomeLongClickAdapter extends BaseAdapter
{
	private Context mContext;
	private String[] mArr;

	public HomeLongClickAdapter(Context context, String[] arr)
	{
		mContext = context;
		mArr = arr;
	}

	@Override
	public int getCount()
	{
		return mArr.length;
	}

	@Override
	public Object getItem(int position)
	{
		return null;
	}

	@Override
	public long getItemId(int position)
	{
		return 0;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup parent)
	{
		View view = LayoutInflater.from(mContext).inflate(R.layout.home_long_click_listitem, null);
		
		ImageView iconIv = (ImageView) view.findViewById(R.id.list_item_icon);
		TextView iconTv = (TextView) view.findViewById(R.id.list_item_info);
		
		if(0 == position)
		{
			if(mArr[0].equals("置顶"))
				iconIv.setImageResource(R.drawable.icon_top);
			else
				iconIv.setImageResource(R.drawable.icon_down);
			
		}
		else if(1 == position)
		{
			iconIv.setImageResource(R.drawable.icon_delete);
		}
		
		iconTv.setText(mArr[position]);
		
		return view;
	}
}



listview_item:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/list_item_icon"
        android:layout_width="30dip"
        android:layout_height="30dip"
        android:layout_centerVertical="true"
        android:layout_marginBottom="25dip"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="25dip"
        android:src="@drawable/icon_top" />

    <TextView
        android:id="@+id/list_item_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginBottom="25dip"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="25dip"
        android:layout_toRightOf="@+id/list_item_icon"
        android:text="置顶"
        android:textColor="@color/black"
        android:textSize="18dip" />

</RelativeLayout>


代码都贴出了,图片资讯什么的就不加上去了。
如有需要,可以联系我:liucanwen517@gmail.com
  • 大小: 21.6 KB
0
0
分享到:
评论

相关推荐

    andorid dialog 大合集

    //点击后弹出窗口选择了第几项 showDialog("你选择的id为" + which + " , " + mItems[which]); } }); break; case DIALOG_3: mProgressDialog = new ProgressDialog(MainDialog.this); mProgressDialog....

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制发送...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制发送...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制发送...

    Google Android SDK开发范例大全的目录

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制-p155 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制...

    Google+Android+SDK开发范例大全

    4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制 5.1 具有正则表达式的TextView...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制...

    Google Android sdk 开发范例大全 部分章节代码

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制-p155 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制...

    Google Android SDK 开发范例大全01

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制-p155 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制...

    Google Android SDK 开发范例大全02

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制-p155 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制...

    Google Android SDK开发范例大全(完整版)

    4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON图标 第5章 交互式通信服务与手机控制 5.1 具有正则表达式的TextView——Linkify规则 5.2 ACTION!CALL!拨打电话——Intent.ACTION.CALL的使用 5.3 自制发送...

Global site tag (gtag.js) - Google Analytics