popupwindow与listview结合使用时,点击后退键无效问题
来源:互联网 发布:mysql 联合唯一键用法 编辑:程序博客网 时间:2024/05/31 13:14
以下是popupwindow和listview结合使用的例子:
使用的参数说明
Context context, 上下文
ArrayList<String> mServicesName, listview显示的数据
TextView mSelectServiceTextView, 控件
final PopupWindowOnItemClickListener postService listview点击时,触发监听器
//创建一个和mSelectServiceTextView宽度一样大小的listview
ListView listView = new ListView(context);
listView.setLayoutParams(new LayoutParams(mSelectServiceTextView.getWidth(), LayoutParams.WRAP_CONTENT));
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
for (String mServiceName : mServicesName) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("coin_service", mServiceName);
list.add(map);
}
String[] from = new String[]{"coin_service"};
int[] to = new int[]{R.id.coin_service};
SimpleAdapter adapter = new SimpleAdapter(context, list, R.layout.item_coin_service, from, to);
listView.setAdapter(adapter);
listView.setFocusableInTouchMode(true);
listView.setFocusable(true);
listView.setBackgroundColor(new Color().WHITE);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
postService.postItem(position);
}});
//创建一个装listview的popupwindow
final PopupWindow popupWindow = new PopupWindow(listView, mSelectServiceTextView.getWidth(), LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(mSelectServiceTextView, 0, 0);
//使其聚集 必须要设置为true,不然listview将无法获取焦点
popupWindow.setFocusable(true);
//设置允许在外点击消失
popupWindow.setOutsideTouchable(true);
//刷新状态
popupWindow.update();
public interface PopupWindowOnItemClickListener {
public void postItem(int position);
}
这过程中,会发现,当popupwindow显示时,后退键和其他控件的点击事件失效掉,此时以下方法能解决问题:
popupWindow.setBackgroundDrawable(new BitmapDrawable()); //这句能解决后退键失效问题
希望能解决你的问题,谢谢!
- popupwindow与listview结合使用时,点击后退键无效问题
- Android中 PopupWindow 与 ListView 结合使用
- PopupWindow+ListView item 点击无效解决办法
- ListView点击无效与ListView里有Button实现问题
- 使用popupWindow时,当点击listView,没有效果
- popupwindow中ListView item点击事件无效的解决方案
- Android 自定义PopupWindow 实现 ListView与PopupWindow结合下拉框
- listview与ratingbar结合点击失去焦点问题
- 解决listview与scrollview结合使用时出现的问题
- 解决listview与scrollview结合使用时出现的问题
- 解决listview与scrollview结合使用时出现的问题
- android popupwindow 中listview 无法点击问题
- PopupWindow中ListView无法点击的问题
- ListView的setOnItemClickListener点击无效问题
- 解决listview onitemclick 点击无效问题
- listview 与checkbox结合记录点击数据
- scollView与ListView结合使用
- CheckBox与ListView结合使用
- 2014年1月16日--1月22日(共18小时,剩4715小时)
- 寒假第四天--排序--海选女主角
- 寒假第四天--排序--冒泡排序中数据交换的次数
- Python编程学习初步
- 企业级hadoop安装
- popupwindow与listview结合使用时,点击后退键无效问题
- 寒假第四天--排序--排序问题
- - RPATH RUNPATH 和 LD_LIBRARY_PATH
- 一位有着20年经验的企业家告诉创业者的5件事
- Java 的 BufferReader 分析
- Makefile中include、-include、sinclude的区别
- flume-ng-extends
- GDB 高级使用
- 寒假第四天--排序--排序