Listview 与2.3及更高版本的listfragments、tabhost和simple curson适配器的兼容性

Listview 与2.3及更高版本的listfragments、tabhost和simple curson适配器的兼容性,listview,android-listview,android-asynctask,android-tabhost,android-2.3-gingerbread,Listview,Android Listview,Android Asynctask,Android Tabhost,Android 2.3 Gingerbread,我正在创建应用程序来加载特定公司的推文。为了使它与Android2.3及更高版本兼容,我需要使用FragmentActivity&ListFragment。我使用AsyncTask在FragmentAcitivity类中的AppStart上获得推文,并添加选项卡,同时将它们加载到sqlite数据库中。现在,在tab-click上,我需要从sqllite数据库加载这些tweet,我正在使用LoaderManager,但是tab-click上没有显示任何内容。以下是我的代码片段: 碎片活动:

我正在创建应用程序来加载特定公司的推文。为了使它与Android2.3及更高版本兼容,我需要使用FragmentActivity&ListFragment。我使用AsyncTask在FragmentAcitivity类中的AppStart上获得推文,并添加选项卡,同时将它们加载到sqlite数据库中。现在,在tab-click上,我需要从sqllite数据库加载这些tweet,我正在使用LoaderManager,但是tab-click上没有显示任何内容。以下是我的代码片段:

碎片活动:

     @Override
    public void onTabChanged(String tag) {  
Log.d(TAG, "onTabChanged");  
TabInfo newTab = this.mapTabInfo.get(tag);  
if (mLastTab != newTab) {  
  FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();  
if (mLastTab != null) {  
if (mLastTab.fragment != null) {  
 ft.detach(mLastTab.fragment);  
 }  
}  
if (newTab != null) {  
if (newTab.fragment == null) {  
newTab.fragment = (ListFragment) ListFragment.instantiate(this, newTab.clss.getName(), newTab.args);  
ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);  
} else {ft.attach(newTab.fragment);  
}  
}     
mLastTab = newTab;  
ft.commit();  
this.getSupportFragmentManager().executePendingTransactions();  
}    
}  
列表片段:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {  
Log.d(TAG, "onCreateView");  
if (container == null) {  
return null;  
}   
adapter = new SimpleCursorAdapter(getActivity().getApplicationContext(), R.layout.row, null,TweetStatusProvider.FROM,TweetStatusProvider.TO,CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);  
adapter.setViewBinder(VIEW_BINDER);  
getLoaderManager().initLoader(STATUS_LOADER, null, this);  
Log.d(TAG, "initLoader executed");  
View view = inflater.inflate(R.layout.list_fragment_layout, container, false);      
ListView listView = (ListView)view.findViewById(android.R.id.list);  
listView.setAdapter(adapter);  
return view;  
}  
布局: main.xml:

 <?xml version="1.0" encoding="utf-8"?>  
 '<'TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
  android:id="@android:id/tabhost"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent" '>'  
'<'LinearLayout  
android:layout_width="match_parent"  
android:layout_height="match_parent"  
android:background="@drawable/background"  
android:orientation="vertical"  
android:padding="10dp" '>'  
'<'HorizontalScrollView  
android:layout_width="match_parent"  
android:layout_height="wrap_content"  
android:scrollbars="none" '>'  
'<'TabWidget  
android:id="@android:id/tabs"  
android:layout_width="54dp"  
android:layout_height="60dp" '/>'  

'<'/HorizontalScrollView'>'  
'<'FrameLayout  
android:id="@android:id/tabcontent"  
android:layout_width="match_parent"  
android:layout_height="match_parent"  
android:padding="5dp" '>'  
'<'/FrameLayout'>'  
'<'FrameLayout  
android:id="@+android:id/realtabcontent"  
android:layout_width="fill_parent"  
android:layout_height="0dp"  
android:layout_weight="1" /'>'  
'<'/LinearLayout'>'  
'<'/TabHost'>'  

''  
''  
''  
''  
''  
''  
''  
''  
''  
''  
list_fragment_layout.xml:

 '<'?xml version="1.0" encoding="utf-8"?'>'  
 '<'LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     
 android:layout_width="match_parent"    
 android:layout_height="match_parent"    
 android:orientation="vertical" '>'    

 '<'ListView  
 android:id="@android:id/list"  
 android:layout_width="match_parent"  
 android:layout_height="wrap_content" '>'  
 '<'/ListView'>'    
'<'/LinearLayout'>'  
“”
''    
''  
''    
''  
row.xml:

'<'?xml version="1.0" encoding="utf-8"?'>'  
'<'RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent" '>'  
    '<'TextView  
 android:id="@+id/text_user"  
 android:layout_width="wrap_content"  
 android:layout_height="wrap_content"  
 android:layout_alignParentLeft="true"  
 android:layout_alignParentTop="true"  
 android:text="Large Text"  
 android:textAppearance="?android:attr/textAppearanceLarge" /'>'  

'<'TextView  
 android:id="@+id/text_created_at"  
 android:layout_width="wrap_content"  
 android:layout_height="wrap_content"  
 android:layout_alignParentRight="true"  
 android:layout_alignParentTop="true"  
 android:text="10 minutes ago"  
 android:textAppearance="?android:attr/textAppearanceMedium" /'>'  
'<'TextView  
  android:id="@+id/text_text"  
  android:autoLink="all"  
      android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_alignParentLeft="true"  
  android:layout_alignParentRight="true"  
  android:layout_below="@+id/text_user"  
  android:text="Small Text"  
  android:textAppearance="?android:attr/textAppearanceSmall" /'>'  
'<'/RelativeLayout'>'  
“”
''  
''  
''  
''  
''  

仅供参考,这是非常多的信息。如果你删除了不必要的代码,你将更有可能很快得到答案。我不确定代码的哪一部分造成了问题,所以我在这里添加了丢失的信息。标签出现在2.3版中,但没有发生任何事情。有人能在这里提出建议吗?还在等待解决方案吗?老兄,就像我说的。没有人会浏览整个项目并为您调试它。花点时间,试着找出问题所在。然后人们会对帮助你找到解决方案更感兴趣。