我正在tabs
我的activity
. 我有 5 个选项卡,每个选项卡都包含一个listview
(我通过 asynctask 获取列表视图的内容)
那是图像:
现在代码:
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
ab.setSelectedNavigationItem(position);
}
});
this.getSherlockActivity().getSupportActionBar().removeAllTabs();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
com.actionbarsherlock.app.ActionBar.Tab tab1 = ab
.newTab()
.setText("Samsung")
.setTabListener(
new TabListener<SamsungLB>(this.getSherlockActivity(),
"tabone", SamsungLB.class));
com.actionbarsherlock.app.ActionBar.Tab tab2 = ab
.newTab()
.setText("HTC")
.setTabListener(
new TabListener<HTCLB>(this.getSherlockActivity(),
"tabtwo", HTCLB.class));
com.actionbarsherlock.app.ActionBar.Tab tab3 = ab
.newTab()
.setText("LG")
.setTabListener(
new TabListener<LGLB>(this.getSherlockActivity(),
"tabthree", LGLB.class));
com.actionbarsherlock.app.ActionBar.Tab tab4 = ab
.newTab()
.setText("Sony")
.setTabListener(
new TabListener<SonyLB>(this.getSherlockActivity(),
"tabfour", SonyLB.class));
com.actionbarsherlock.app.ActionBar.Tab tab5 = ab
.newTab()
.setText("Search")
.setTabListener(
new TabListener<SearchLB>(this.getSherlockActivity(),
"tabfive", SearchLB.class));
ab.addTab(tab1);
ab.addTab(tab2);
ab.addTab(tab3);
ab.addTab(tab4);
ab.addTab(tab5);
return rootView;
}
@SuppressLint("NewApi")
public static class TabListener<T extends SherlockFragment> implements
ActionBar.TabListener {
private Fragment mFragment;
private final Activity mActivity;
private final String mTag;
private final Class<T> mClass;
public TabListener(Activity activity, String tag, Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
public void onTabReselected(Tab arg0,
android.app.FragmentTransaction arg1) {
}
@SuppressLint("NewApi")
public void onTabSelected(Tab arg0, android.app.FragmentTransaction arg1) {
mViewPager.setCurrentItem(arg0.getPosition());
}
public void onTabUnselected(Tab arg0,
android.app.FragmentTransaction arg1) {
}
@Override
public void onTabSelected(com.actionbarsherlock.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(
com.actionbarsherlock.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(
com.actionbarsherlock.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
基本上,每个选项卡都有一个通过 AsyncTask 填充的列表视图。我通过 JSON 得到结果并解析它们。后来我通过图像加载器解析图像。为什么会滞后???特别是当我从 LG 更改为 HTC 时。(即使在那里应用程序有时也会关闭!)。谢谢你的帮助将不胜感激:)
更新:所有选项卡都使用相同的布局文件。
代码:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
请帮忙。