package com.example.mrwuchao.fragmenttest;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.util.ArrayList;
/**
-
Created by Mr.wuchao on 2016/5/17.
*/
public class FirstFragment extends ListFragment {
ArrayList arrayList = new ArrayList<>();
public FirstFragment() {
super();
}@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
FragmentManager manager = getFragmentManager();
FragmentTransaction fra = manager.beginTransaction();
fra.add(R.id.frame,new SecondFragment(),"test");
System.out.println(fra.isAddToBackStackAllowed());
fra.addToBackStack(null);
fra.commit();
}@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
arrayList.add("娱乐");
arrayList.add("新闻");
arrayList.add("足球");
arrayList.add("篮球");
arrayList.add("八卦");
ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), R.layout.fragment1,
arrayList);
setListAdapter(arrayAdapter);}
}
这是主要的内容 其他的就是简单的布局和实现类,我在fra中将添加fragment的动作加入后退栈,但是按后退键直接退出了activity,这是为什么呀