@Override
public int getCount() {
return mFragments.size();
}
@Override
public Fragment getItem(int arg0) {
return mFragments.get(arg0);
}
}
InfoPageFragment(ArrayList<String> entities, int type) {
Log.i("Entity:", String.valueOf(type));
this.entities = entities;
infotype = type;
keys = new ArrayList<String>(entities.size());
}
private ArrayList<Map<String, Object>> getData() {
String[] info = null;
Map<String, Object> infomap = null;
ArrayList<Map<String, Object>> listviewdata = new ArrayList<Map<String, Object>>();
Log.i("Data", String.valueOf(infotype));
for (int i = 0; i < entities.size(); i++) {
info = entities.get(i).split(String.valueOf('\u0216'));
if (info.length != 3) {
continue;
}
infomap = new LinkedHashMap<String, Object>();
infomap.put("txt_infodata", info[1]);
infomap.put("txt_infodate", info[2]);
listviewdata.add(infomap);
keys.add(info[0]);
}
return listviewdata;
}
private void initListView(View view) {
ListView lst_info = (ListView) view.findViewById(R.id.lst_infolist);
lst_info.setAdapter(new SimpleAdapter(view.getContext(), getData(),
R.layout.listitem_info, new String[] { "txt_infodata",
"txt_infodate" }, new int[] { R.id.txt_infodata,
R.id.txt_infodate }));
lst_info.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String dir = null;
switch (infotype) {
case 0:
dir = mApp.getFile(mApp.Pag_News);
break;
case 1:
dir = mApp.getFile(mApp.Pag_Rule);
break;
case 2:
dir = mApp.getFile(mApp.Pag_Download);
break;
}
Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(dir
+ keys.get(arg2)));
arg1.getContext().startActivity(it);
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_newslist, container,
false);
initListView(view);
return view;
}
}
public void presentFragment(int id) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = initFragment(id);
ft.replace(R.id.fragment_container, fragment);
ft.commit();
preSelected = id;
}
构造是碎片[ViewPager [3 Fragment]] 当我第一次启动viewpager(内部有3个片段)时,它可以完美地工作,但是当我替换另一个片段并替换它时,片段1和片段3可以复习,但片段2是空白的!我是android开发的新手,很长一段时间都对这个问题很疯狂!!!
我是android devolopment的新手