Fragment容器Activity

1//file NoteListActivity 2package jp.co.ricoh.melody.views.activities; 3 4import android.databinding.DataBindingUtil; 5import android.os.Bundle; 6import android.support.annotation.Nullable; 7import android.support.v4.app.Fragment; 8import android.support.v4.app.FragmentTransaction; 9 10import junit.framework.Test; 11 12import jp.co.ricoh.melody.R; 13import jp.co.ricoh.melody.databinding.NoteListActivityBinding; 14import jp.co.ricoh.melody.presenters.INoteListActivityPresenter; 15import jp.co.ricoh.melody.presenters.NoteActivityPresenter; 16import jp.co.ricoh.melody.presenters.NoteListActivityPresenter; 17import jp.co.ricoh.melody.views.fragments.NoteListFragment; 18 19import static android.R.attr.fragment; 20 21/** 22 * Created by leonard on 17-3-11. 23 */ 24public class NoteListActivity extends BaseActivity implements NoteActivityPresenter { 25 26    private NoteListActivityBinding mViewDataBinding; 27    private INoteListActivityPresenter mActivityPresenter; 28    private Fragment mCurrentFragment; 29 30    @Override 31    protected void onCreate(@Nullable Bundle savedInstanceState) { 32        super.onCreate(savedInstanceState); 33        initView(savedInstanceState); 34    } 35 36   /* this contain all note functions. 37   * content layout contain note list layout,note item layout,layout item edit 38   * back key will change in fragemnt backstack 39   * */ 40 41    private void initView(Bundle savedInstanceState) { 42        mViewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_note); 43        mActivityPresenter = NoteListActivityPresenter.newInstance(); 44        if (savedInstanceState==null) { 45            Fragment fragment = NoteListFragment.newInstance(); 46            switchContent(fragment,true); 47        } 48    } 49    @Override 50    public void switchContent(Fragment newFragemnt, boolean reuse) { 51        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction().setCustomAnimations( 52                android.R.anim.fade_in, android.R.anim.fade_out); 53        if (reuse){ 54            newFragemnt = getSupportFragmentManager().findFragmentByTag(newFragemnt.getTag()); 55        } 56        if (!newFragemnt.isAdded()) {    // 先判断是否被add过 57            transaction.hide(mCurrentFragment).add(R.id.contentFrame, newFragemnt).commitAllowingStateLoss(); // 隐藏当前的fragment,add下一个到Activity中 58        } else { 59            transaction.hide(mCurrentFragment).show(newFragemnt).commitAllowingStateLoss(); // 隐藏当前的fragment,显示下一个 60        } 61        mCurrentFragment = newFragemnt; 62    } 63 64    @Override 65    public void setTitle(String title) { 66        mViewDataBinding.toolbar.setTitle(R.string.app_name); 67    } 68} 69 70//file NoteActivityPresenter 71 72package jp.co.ricoh.melody.presenters; 73 74import android.support.v4.app.Fragment; 75 76/** 77 * Created by leonard on 17-3-13. 78 */ 79public interface NoteActivityPresenter { 80    void switchContent(Fragment newFragemnt, boolean reuse); 81    void setTitle(String title); 82} 83 84//res activity_note 85<?xml version="1.0" encoding="utf-8"?> 86<layout xmlns:android="http://schemas.android.com/apk/res/android" 87    xmlns:app="http://schemas.android.com/apk/res-auto" 88    android:layout_width="match_parent" 89    android:layout_height="match_parent"> 90 91    <data class="NoteListActivityBinding"/> 92 93    <android.support.design.widget.CoordinatorLayout 94        android:layout_width="match_parent" 95        android:layout_height="match_parent"> 96     <include layout="@layout/content_main" 97         android:id="@+id/content" 98            android:layout_height="match_parent" 99            app:layout_behavior="@string/appbar_scrolling_view_behavior" 100            android:layout_width="match_parent"/> 101 102 103        <android.support.design.widget.AppBarLayout 104            android:layout_width="match_parent" 105            android:fitsSystemWindows="true" 106            android:layout_height="?attr/actionBarSize"> 107            <android.support.v7.widget.Toolbar 108                android:id="@+id/toolbar" 109                android:layout_width="match_parent" 110                android:layout_height="wrap_content"></android.support.v7.widget.Toolbar> 111        </android.support.design.widget.AppBarLayout> 112 113    </android.support.design.widget.CoordinatorLayout> 114</layout> 115 116//res content_main 117<?xml version="1.0" encoding="utf-8"?> 118<!-- Copyright (C) 2016 RICOH Co.,LTD. --> 119<!-- All rights reserved. --> 120<RelativeLayout 121    xmlns:android="http://schemas.android.com/apk/res/android" 122    android:layout_width="match_parent" 123    android:layout_height="match_parent" 124    android:orientation="horizontal"> 125 126    <FrameLayout 127        android:id="@+id/contentFrame" 128        android:layout_width="match_parent" 129        android:layout_height="match_parent"> 130    </FrameLayout> 131 132 133</RelativeLayout>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Fragment容器Activity - HelloWorld