展会信息港展会大全

android开发之 popup + listview 使用
来源:互联网   发布日期:2015-11-26 09:33:09   浏览:1581次  

导读:popup +GridView使用。本想把list数据以button形式显示出来,可是发现点击button时,不能监听到每个item的点击事件1.[代码][Java]代码private void showPopupWindow(){if(window == null){LayoutInflater ......

popup +GridView使用。本想把list数据以button形式显示出来,可是发现点击button时,不能监听到每个item的点击事件

1. [代码][Java]代码

private void showPopupWindow(){

if(window == null){

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view = inflater.inflate(R.layout.goods_detail_popupwindow, null);

cancle_button = (ImageView) view.findViewById(R.id.cancle_popup);

goods_filed = (TextView) view.findViewById(R.id.goods_filed);

goods_color_grid = (GridView) view.findViewById(R.id.color_grid);

goods_color_grid.setOnItemClickListener(this);

// goods_size_grid = (GridView) view.findViewById(R.id.size_grid);

// goods_size_grid.setOnItemClickListener( this);

window = new PopupWindow(view ,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

window.update();

window.setFocusable(true);

window.setTouchable(true);

//设置点击外部取消ppwindow

window.setOutsideTouchable(true);

//这里并不是改变其背景,是让点击back键能dimm popupwindow,至于为什么,我也不知道

window.setBackgroundDrawable(new BitmapDrawable());

cancle_button.setOnClickListener(this);

cancle_button.setOnTouchListener(new OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

// TODO Auto-generated method stub

// 如果点击了popupwindow的外部,popupwindow也会消失

if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {

window.dismiss();

return true;

}

return false;

}

});

}

//设置popup显示的坐标

window.showAtLocation(ll, Gravity.RIGHT | Gravity.TOP, 10,150);

}

private void setGoodsColorPopup(){

String s ="zhang";

List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();

for(int i=0;i<5;i++){

Map<String,Object> m=new HashMap<String,Object>();

m.put(s, "shuai" + i);

list.add(m);

}

goods_filed.setText("商品属性");

Log.i(TAG, " list " +list);

SimpleAdapter goodsSizeAdapter= new SimpleAdapter(getApplicationContext(), list,

R.layout.goods_detail_popupwindow_include, new String[]{s}, new int[]{R.id.goods_size_button});

goods_color_grid.setAdapter(goodsSizeAdapter);

}

《===========goods_detail_popupwindow。xml======》

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

android:background="@drawable/test"

>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textSize="18sp"

android:id="@+id/goods_filed"

/>

<GridView

android:id="@+id/color_grid"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:numColumns="3"

android:verticalSpacing="3dp"

android:horizontalSpacing="3dp"

android:columnWidth="100dip"

android:stretchMode="columnWidth"

android:gravity="center"

/>

<!-- <TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/size"

android:textStyle="bold"

android:textSize="26sp"

android:text="选择尺码"

/>

<GridView

android:id="@+id/size_grid"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:numColumns="5"

android:verticalSpacing="3dp"

android:horizontalSpacing="3dp"

android:columnWidth="60dip"

android:stretchMode="columnWidth"

android:gravity="center"

/> -->

<RelativeLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<TextView

android:id="@+id/pp_price"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="18sp"

android:text="价格:68.00"

/>

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/cancle_popup"

android:src="@drawable/pp_subimt"

android:layout_toRightOf="@id/pp_price"

android:paddingLeft="300dip"

/>

</RelativeLayout>

</LinearLayout>

《===========goods_detail_popupwindow_include。xml======》

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

>

<!-- <Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/goods_size_button"

android:focusable="false"

/> -->

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/goods_size_button"/>

</LinearLayout>

赞助本站

人工智能实验室

相关热词: popup

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港