2014-04-05 83 views
0

我閱讀本教程以創建一個具有ListView的導航抽屜。 鏈接:http://developer.android.com/training/implementing-navigation/nav-drawer.html如何在ListView(android)中添加部分?

如何將我的ListView分割爲多個部分併爲每個部分添加標題? (如Facebook應用程序)。我閱讀了很多示例和教程,但沒有人會非常清楚。 我必須重寫適配器的getView方法嗎?或.. 我希望有人知道如何回答清楚。謝謝!!

這是我的代碼:

public class NoLeague extends Activity{ 

    private ListView listView; 
    private DrawerLayout drawerLayout; 
    private String[] items = {"Lega_1","Lega_2", "Option", "Logout"}; 


    @Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getActionBar().setBackgroundDrawable(getResources(). 
      getDrawable(R.drawable.banner)); 

     getActionBar().setTitle("TITOLOdiPROVA"); 
     setContentView(R.layout.noleague_layout); 

     listView = (ListView) findViewById(R.id.left_drawer); 
     drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 


     listView.setAdapter(new ArrayAdapter<String>(this, 
      R.layout.item_layout, items)); 

    } 
} 

這是item_layout:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceListItemSmall" 
    android:gravity="center_vertical" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:textColor="#fff" 
    android:background="?android:attr/activatedBackgroundIndicator" 
    android:minHeight="?android:attr/listPreferredItemHeightSmall"/> 

這是我的抽屜式導航欄的佈局:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- The main content view --> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@drawable/noleague_image" > 
    </LinearLayout> 

      <!-- The navigation drawer --> 
      <ListView 
       android:id="@+id/left_drawer" 
       android:layout_width="240dp" 
       android:layout_height="match_parent" 
       android:layout_gravity="start" 
       android:choiceMode="singleChoice" 
       android:divider="#575555" 
       android:dividerHeight="1dp" 
       android:background="#111" /> 

</android.support.v4.widget.DrawerLayout> 

回答

相關問題