android 在fragment中如何监听返回键,home键
来源:互联网 发布:淘宝上传商品怎么分类 编辑:程序博客网 时间:2024/05/29 15:45
原文地址:http://wujierd.iteye.com/blog/2104153
在activity中用keydown很容易实现对返回键的监听,但是这个函数不能再fragment中重载。
通过我呕心沥血的寻找,终于找到了解决办法,对其他物理按键的监听也同理。- public class phonerecorder extends Fragment {
- View listview;
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- listview = (View) inflater.inflate(R.layout.phonerecorder, null);
- mListView = (ListView) listview.findViewById(R.id.listView);
- init();
- mListView.setOnItemClickListener(clickitemlistener);
- listview.setFocusable(true);//这个和下面的这个命令必须要设置了,才能监听back事件。
- listview.setFocusableInTouchMode(true);
- listview.setOnKeyListener(backlistener);
- return listview;
- }
- private View.OnKeyListener backlistener = new View.OnKeyListener() {
- @Override
- public boolean onKey(View view, int i, KeyEvent keyEvent) {
- if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
- if (i == KeyEvent.KEYCODE_BACK) { //表示按返回键 时的操作
- if (!rootpatch.equals(currentfilepach) && currentfilepach != null) {
- File file = new File(currentfilepach);
- openDir2(file.getParent().toString());
- currentfilepach = file.getParent().toString();
- return true;
- } //后退
- return false; //已处理
- }
- }
- return false;
- }
- };
- }
0 0
- android 在fragment中如何监听返回键,home键
- android 在fragment中如何监听返回键,home键
- android 在fragment中如何监听返回键,home键
- android 在fragment中怎么监听返回键,home键
- 在fragment中监听返回键,home键
- Android 在Fragment中监听返回键的做法
- 在Fragment中监听返回键
- 如何在activity中监听Home键
- Android Fragment中监听返回键
- android fragment 监听返回键
- Android fragment监听返回键
- Fragment中监听返回键
- Fragment中监听返回键
- Android开发中如何监听用户的home键
- fragment监听返回键
- Fragment监听返回键
- Fragment 监听返回键
- Fragment监听返回键
- Java异常之catch语句块
- 2015.11.16,Demo10,6.2处理对象,面向接口编程
- resources.arsc格式(包->类型->资源项)
- 08(maven+SSH)之使用nexus搭建maven私有服务器
- listView的简单用法
- android 在fragment中如何监听返回键,home键
- property_get/property_set
- LightOJ 1050 - Marbles (概率dp)
- 两层网络下,实现PC同时访问AC、AP操作方法。
- ListView的优化
- 为Ubuntu 14.04右键添加终端的设置
- 09(maven+SSH)之使用jersey实现应用服务器和图片服务器分离
- 2015.11.17,Demo11,枚举类,垃圾回收机制,使用jar的压缩,键盘输入,字符串后添加字符,格式化输出日期
- 女:我生病了 男:多喝水? 呵呵哒...