ListView点击item底部弹出popupWindow删除、修改、取消选择框
2016-10-01 10:34
489 查看
先看一下效果:
点击单个item弹出选择框,可以选择删除或者修改。删除单条item,或者跳转到修改页面。
listview的布局:
popupWindow的布局:
这里遇到个坑,如果不加上面透明的View的话,会出现,点击了一个item后,在不取消的情况下,再点击其它的item,会再弹出来一个popupWindow。造成重复叠加,再点删除的话无法判断是哪个item。设置无效。所有没办法只能加了个View,来把上面可聚焦的部分给遮盖掉。
popupWindow的Style:
这里引用了两个动画,一个是弹出的shipping_popup_show。和消失的shipping_popup_hide
在anim中创建两个文件
shipping_popup_show:
shipping_popup_hide:
Activity中listview的监听事件中:
这里在编辑事件跳转之前,一定要调用一下.dismiss。不然从详情页返回的时候popupWindow依然存在。
MinuteActivity中获取数据并展示
实体类继承Serializable方法。在这里可以用的到。下面是三个EditText编辑控件
有不清楚的地方可以留言。
如有不妥,欢迎指正!
点击单个item弹出选择框,可以选择删除或者修改。删除单条item,或者跳转到修改页面。
listview的布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/shipping_address_ll" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:gravity="center_vertical" android:orientation="vertical" android:paddingLeft="@dimen/dp_15"> <TextView android:id="@+id/shipping_address_name" android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center_vertical" android:text="姓名:张三" android:textSize="@dimen/sp_12" /> <TextView android:id="@+id/shipping_address_phone" android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center_vertical" android:text="手机号:13800138000" android:textSize="@dimen/sp_12" /> <TextView android:id="@+id/shipping_address_site" android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center_vertical" android:text="收货地址:北京市海淀区上地东二路上地佳园" android:textSize="@dimen/sp_12" /> </LinearLayout>
popupWindow的布局:
这里遇到个坑,如果不加上面透明的View的话,会出现,点击了一个item后,在不取消的情况下,再点击其它的item,会再弹出来一个popupWindow。造成重复叠加,再点删除的话无法判断是哪个item。设置无效。所有没办法只能加了个View,来把上面可聚焦的部分给遮盖掉。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> <Button android:id="@+id/tv_delete" android:layout_width="match_parent" android:layout_height="60dp" android:text="删除"/> <Button android:id="@+id/tv_set" android:layout_width="match_parent" android:layout_height="60dp" android:text="修改"/> <Button android:id="@+id/tv_cancel" android:layout_width="match_parent" android:layout_height="60dp" android:text="取消"/> </LinearLayout>
popupWindow的Style:
这里引用了两个动画,一个是弹出的shipping_popup_show。和消失的shipping_popup_hide
<!--popupwindow效果--> <style name="shipping_popup_style"> <item name="android:windowFrame">@null</item> <item name="android:background">#00000000</item> <!-- 设置自定义布局的背景透明 --> <item name="android:windowEnterAnimation">@anim/shipping_popup_show</item> <item name="android:windowExitAnimation">@anim/shipping_popup_hide</item> <item name="android:windowBackground">@color/bgColor_overlay</item> <!-- 设置window背景透明,也就是去边框 --> <item name="android:backgroundDimEnabled">false</item> </style>
在anim中创建两个文件
shipping_popup_show:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="0" android:fromYDelta="120" android:toYDelta="0" android:duration="500" android:fillEnabled="true" android:fillAfter="true"/> </set>
shipping_popup_hide:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="0" android:fromYDelta="0" android:toYDelta="120" android:duration="500" android:fillEnabled="true" android:fillAfter="true"/> </set>
Activity中listview的监听事件中:
这里在编辑事件跳转之前,一定要调用一下.dismiss。不然从详情页返回的时候popupWindow依然存在。
@Override public void onItemClick(AdapterView<?> adapterView, final View view, final int i, long l) { View view1 = LayoutInflater.from(this).inflate(R.layout.popupwindow_layout,null);//PopupWindow对象 popupWindow=new PopupWindow(this); //设置PopupWindow布局 popupWindow.setContentView(view1); //设置动画 popupWindow.setAnimationStyle(R.style.shipping_popup_style); //设置PopupWindow宽 popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); //设置PopupWindow高 popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); //在父布局的弹入/出位置 rootView =LayoutInflater.from(this).inflate(R.layout.shipping_address, null); popupWindow.showAtLocation(rootView, Gravity.CENTER,0,0); //返回键点击,弹出 popupWindow.setFocusable(false); //实例化控件 bt_set= (Button) view1.findViewById(R.id.bt_set); bt_cancel= (Button) view1.findViewById(R.id.bt_cancel); bt_delete= (Button) view1.findViewById(R.id.bt_delete); bt_set.setOnClickListener(this); bt_cancel.setOnClickListener(this); bt_delete.setOnClickListener(this); //删除 bt_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view1) { if (i<name.length) { //删除该条item list.remove(i); //关闭PopupWindow popupWindow.dismiss(); } // 刷新布局 adapter.notifyDataSetChanged(); } }); //编辑 bt_set.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ShippingAddressBean bean=list.get(i); Intent intent=new Intent(ShippingAddressActivity.this, ShippingAddressMinuteActivity.class); //封装数据包 Bundle bundle = new Bundle(); //传入对应的key,value bundle.putSerializable("date",bean); //发送到详情页 intent.putExtras(bundle); popupWindow.dismiss(); //执行 有返回结果的 跳转 startActivityForResult(intent, 0); } }); //取消 bt_cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { popupWindow.dismiss(); } }); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { } }); }
MinuteActivity中获取数据并展示
实体类继承Serializable方法。在这里可以用的到。下面是三个EditText编辑控件
/**读取Activity传过来的数据 */ Intent intent=getIntent(); ShippingAddressBean notebean=(ShippingAddressBean) intent.getSerializableExtra("date"); /**指定传过来的数据在当前页展示的位置*/ shipping_minute_name.setText(notebean.getName()); shipping_minute_phone.setText(notebean.getPhone()); shipping_minute_site.setText(notebean.getAddress());
有不清楚的地方可以留言。
如有不妥,欢迎指正!
相关文章推荐
- Android--GridView/ListView 点击Item修改Item背景 标识是当前选择项方法
- Android--GridView/ListView 点击Item修改Item背景 标识是当前选择项方法:
- 点击 PopupWindow ,ListView 底部弹出
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 关于在Android中如何点击GridView或者ListView中item子项达到修改子项背景的问题解决方案
- PopupWindow-----listview item的点击出现PopupWindow
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 【Android】Activity和PopupWindow都实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- PopupWindow实现从底部弹出或滑出选择菜单或窗口
- ListView item中的 RadioButton(自定义RadioButton图标,默认无图,选择有图)点击时不显示图片问题
- listview点击item,在item的上边弹出popwindow
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- Android-取消GridView/ListView item被点击时的效果
- 当长时间点击ListView时弹出contextMenu如何确定被点击listView中item的位置
- 关于Android中popupwindow的listview的item点击事件无效的解决方案
- listView点击空间的时候弹出 PopupWindow
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 重写listview,横向滑动出现删除按钮,点击按钮删除item