tabhost切换时点别的按钮再点回来就会将oncreatview方法重复执行,怎样只执行一次? 财富值86

2016-11-02 17:39发布

if(tabId=="tab03"){

                                 //获取管理者权限                 android.app.FragmentManager manager=getFragmentManager();             FragmentTransaction transaction=manager.beginTransaction();             ListViewFragment2 fragment=new ListViewFragment2();             transaction.add(R.id.framlayout,fragment);//容器的ID             transaction.commit();//提交事务             }             这里就是动态添加。。。。                                       然后  public class ListViewFragment2 extends Fragment{   private ListView listview;   private SimpleAdapter simp_adapter;   private List<Map<String,Object>>dataList;   private ArrayAdapter<String>arr_adapter; private View view;     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {                            view=inflater.inflate(R.layout.fragment1, container, false);         listview=(ListView) view.findViewById(R.id.listview1);         dataList=new ArrayList<Map<String,Object>>();         simp_adapter=new SimpleAdapter(getActivity(), getdata(), R.layout.simpleadapter,new String[]{"pic","text"},new int[]{R.id.pic,R.id.text});         listview.setAdapter(simp_adapter);         listview.setItemsCanFocus(true);         }         return view;     }               private List<Map<String,Object>> getdata() {                  for(int i=0;i<20;i++)         {             Map<String,Object>map=new HashMap<String,Object>();             map.put("pic",R.drawable.a);             map.put("text","亚索"+i);             dataList.add(map);         }         return dataList;     }  }                          
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
1条回答

一看你就是新手,哪有这样写的if(tabId=="tab03")
你每次都add一个Fragment,肯定走onCreateView,搜搜Fragment懒加载吧

一周热门 更多>