wemall app商城源码Fragment中监听onKey事件
来源:互联网 发布:photo picture软件 编辑:程序博客网 时间:2024/05/08 21:41
wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改。本文分享android开发Fragment中监听onKey事件主要代码,供技术员参考学习。
项目中越来越多的用到Fragment,下面记录一下在ActionBar中监听Fragment的onKey事件。
ActionBar实现Onkey事件,判断当前的fragment是哪一个,是不是所需要的Fragment,然后在需要监听OnKey事件的Fragment中写一个静态方法,传递keycode与event事件即可。
package info.androidhive.tabsswipe;import info.androidhive.tabsswipe.adapter.TabsPagerAdapter;import android.annotation.SuppressLint;import android.app.SearchManager;import android.content.Context;import android.support.v7.app.ActionBar;import android.support.v7.app.ActionBar.Tab;import android.support.v7.app.ActionBarActivity;import android.support.v7.widget.SearchView;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.view.MenuItemCompat;import android.support.v4.view.ViewPager;import android.util.Log;import android.view.KeyEvent;import android.view.Menu;import android.view.MenuItem;@SuppressLint("NewApi")public class MainActivity extends ActionBarActivity implements ActionBar.TabListener { private ViewPager viewPager; private TabsPagerAdapter mAdapter; private ActionBar actionBar; private Fragment fg; // Tab titles private String[] tabs = { "TopRatedFragment", "GamesFragment", "MoviesFragment" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); actionBar = getSupportActionBar(); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setOffscreenPageLimit(3); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Adding Tabs for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name) .setTabListener(this)); } /** * on swiping the viewpager make respective tab selected * */ viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { public void onPageSelected(int position) { // on changing the page // make respected tab selected// actionBar.setSelectedNavigationItem(position); actionBar.selectTab(actionBar.getTabAt(position)); mAdapter.getItem(position); } public void onPageScrolled(int arg0, float arg1, int arg2) { } public void onPageScrollStateChanged(int arg0) { } }); } @Override public boolean onCreateOptionsMenu(Menu menu) {// SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); getMenuInflater().inflate(R.menu.main, menu); MenuItem searchItem = menu.findItem(R.id.action_settings); SearchView searchview = (SearchView)MenuItemCompat.getActionView(searchItem); searchview.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); return super.onCreateOptionsMenu(menu); } public void onTabReselected(Tab arg0, android.support.v4.app.FragmentTransaction arg1) { // TODO Auto-generated method stub } public void onTabSelected(Tab arg0, android.support.v4.app.FragmentTransaction arg1) { // TODO Auto-generated method stub viewPager.setCurrentItem(arg0.getPosition()); fg = mAdapter.getItem(arg0.getPosition()); Log.d("fg", fg+""); } public void onTabUnselected(Tab arg0, android.support.v4.app.FragmentTransaction arg1) { // TODO Auto-generated method stub } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub Log.d("ActionBar", "OnKey事件"); if(fg instanceof GamesFragment){ GamesFragment.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); }}
原文详情地址:http://git.oschina.net/einsqing/wemall-mobile
wemall-mobile商城详情地址:http://www.koahub.com/home/product/56
wemall官网地址:http://www.wemallshop.com
WeMall - 开源微商城 微信商城 商城源码 分销商城 b2b2c商城系统
0 0
- wemall app商城源码Fragment中监听onKey事件
- Fragment中监听onKey事件
- wemall app商城源码Android短信监听接收器
- wemall app商城源码中android按钮的三种响应事件
- wemall app商城源码Android中ViewHolder详细解释
- wemall app商城源码机器人检测
- Fragment中监听onKey事件,没你想象的那么难。
- wemall app商城源码中ScrollView中嵌套ListView主要代码
- wemall app商城源码中基于PHP的ThinkPHP惯例配置文件代码
- wemall app商城源码中基于JAVA的Android异步加载图片管理器代码
- wemall app商城源码android开发MD5加密工具类
- wemall app商城源码Android数据的SharedPreferences储存方式
- WeMall的Android app商城中的wemall doraemon代码
- wemall app商城源码Android 获取XML网络数据并绑定到ListView
- wemall app商城源码Android之ListView异步加载网络图片(优化缓存机制)
- wemall app商城源码Android之支付宝接口公用函数
- wemall app商城源码Android之支付宝通知处理类
- wemall app商城源码Android之支付宝接口RSA函数
- openwrt shell 变量运算
- C++多线程同步(采用关键代码段即临界区)
- Hub与Switch的帧的广播细节
- 病毒木马查杀实战第025篇:JS下载者脚本木马的分析与防御
- 以Graphicslayer为管理组来管理Element.
- wemall app商城源码Fragment中监听onKey事件
- MySQL函数大全 及用法示例
- ehcache 异常net.sf.ehcache.CacheException: When configured copyOnRead or copyOnWrite, a Store will onl
- java在SAE中使用的相关问题总结
- iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView
- jquery select 插件
- String 的compareto函数
- 不能用ajax提交文件下载的请求
- windows中以本地模式运行spark遇到“Could not locate executable null\bin\winutils.exe in the Hadoop binarie”