自定义fragment抽象父类
来源:互联网 发布:韩火火淘宝店 编辑:程序博客网 时间:2024/06/07 18:24
BaseFragment.java
public abstract class BaseFragment extends Fragment { protected Context mContext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = getActivity(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = initParent(inflater, container); findViews(rootView); setListensers(); return rootView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initVariable(); } private View initParent(LayoutInflater inflater, ViewGroup container) { View rootView = inflater.inflate(R.layout.fragment_base_layout, container, false); LinearLayout subCententView = (LinearLayout) rootView.findViewById(R.id.base_sub_fragment_layout); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); View centerView = View.inflate(mContext, setContentView(), null); subCententView.addView(centerView, layoutParams); return rootView; } /** * 跳转到某个Activity */ protected void gotoActivity(Context mContext, Class<?> toActivityClass, Bundle bundle) { Intent intent = new Intent(mContext, toActivityClass); if (bundle != null) { intent.putExtras(bundle); } mContext.startActivity(intent); ((Activity) mContext).overridePendingTransition(R.anim.push_right_in, R.anim.not_exit_push_left_out); } public void gotoActivityForResult(Context mContext,Intent intent, int requestCode) { super.startActivityForResult(intent, requestCode); ((Activity)mContext).overridePendingTransition(R.anim.push_right_in, R.anim.not_exit_push_left_out); } /** * 初始化子类fragment的变量 */ protected abstract void initVariable(); /** * 加载子类布局 */ protected abstract int setContentView(); /** * 加载控件 */ protected abstract void findViews(View rootView); /** * 设置监听 */ protected abstract void setListensers();}
fragment_base_layout.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/base_sub_fragment_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical" > </LinearLayout></RelativeLayout>
动画文件见博客–android activity自定义父类
阅读全文
2 0
- 自定义fragment抽象父类
- 抽象类管理fragment
- android activity自定义抽象父类
- 采用抽象类优化Fragment提交代码
- 自定义抽象数据类型,即类
- Android 自定义Fragment切换管理类,自动管理Fragment的生命周期,支持FragmentActivity和Fragment里面嵌套fragment
- 自定义ListView+fragment
- 自定义TabHost+Fragment+ViewPager
- Android_自定义View、Fragment
- 抽象父类SqlHelper
- 自定义抽象类CustomSQLiteOpenHelper,实现SQLiteDB自由存储(eg. SDCARD)
- Fragment实现的自定义Dialog
- 自定义控件、Fragment、Handler详解
- Fragment自定义栈的使用
- Fragment viewPager 自定义 异常捕获
- 抽象类 抽象函数
- 抽象类、抽象方法
- 抽象类抽象方法
- 通过sql语句limit标签生成java分页
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- Java数据类型分类
- MFC计算器项目——进制转换模块
- 在MacOS下,设置环境变量
- 自定义fragment抽象父类
- tensorflow基本语法理解
- poj2243--骑士骑马--bfs算法
- 最近两年跟踪算法归纳
- maven常用镜像仓库
- Nodejs创建HTTPS服务器
- python求一个时间点的前一个月和后一个月
- php中GET方法加号变成空格
- 去除list集合中重复项的几种方法