tabhost切换时点别的按钮再点回来就会将oncreatview方法重复执行,怎样只执行一次??
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; }优艾设计网_在线设计}
M14****403 2022-06-29 20:18 优艾设计网_设计LOGO
一看你就是新手,哪有这样写的if(tabId=="tab03")你每次都add一个Fragment,肯定走onCreateView,搜搜Fragment懒加载吧
精彩评论