2013-05-19 73 views
0

在我的應用程序不同的佈局,我有一個列表視圖中使用Web服務,顯示結果的搜索活動。我要添加3個標籤導航(「清單當然」,「點」和「照片」)。 「聆聽」是默認選項卡。點擊「carte」時,結果顯示在地圖上。當點擊「照片」時,它們使用另一種佈局顯示。正是這樣的應用程序:ActionBarSherlock標籤導航 - 相同的列表視圖數據,但每個標籤

enter image description here enter image description here enter image description here

我能夠添加的標籤導航,但我不知道如何顯示使用不同的佈局,每個標籤的結果。

public class SearchableActivity extends SherlockActivity implements ActionBar.TabListener { 
    ListView listViewData; 
    ProductAdapter productAdapter; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.cproduct_list); 

     getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     ActionBar.Tab tab1 = getSupportActionBar().newTab(); 
     tab1.setText("Liste"); 
     tab1.setTabListener(this); 
     getSupportActionBar().addTab(tab1); 

     ActionBar.Tab tab2 = getSupportActionBar().newTab(); 
     tab2.setText("Carte"); 
     tab2.setTabListener(this); 
     getSupportActionBar().addTab(tab2); 

     ActionBar.Tab tab3 = getSupportActionBar().newTab(); 
     tab3.setText("Photo"); 
     tab3.setTabListener(this); 
     getSupportActionBar().addTab(tab3); 

     listViewData = (SwipeListView) findViewById(android.R.id.list); 
     handleIntent(getIntent()); 
    } 
} 

回答

1

你必須使用一個FragmentPagerAdapter併爲每個標籤上,您必須創建一個片段..有示例代碼可以從Android的..

如果您在Eclipse中創建的Android項目,你可以選擇不同的左右導航選項。通過選擇你想要的項目將與實施標籤導航創建的標籤導航選項之一..

+0

謝謝。事情現在更加清晰。這是我的理解:我要創建1個活性(其延伸FragmentActivity所述可搜索的活性),爲每個標籤3個片段,它包含的FrameLayout 1點的佈局,以及佈局3爲每個標籤。 但我的搜索活動調用webservice的,我不知道處理這個問題。如何將Web服務數據傳遞給碎片? – tsil

+0

您可以通過以下鏈接查看是否將數據傳遞給Fragment:http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity – zennon