2014-10-19 61 views
0

我有很多導航抽屜(主要在Google Apps中),其中很少項目沒有列表項目分隔符,而某些列表項目具有列表分隔符。 我想爲我的應用程序實現相同的功能。爲少數列表項目隱藏列表項分隔符

任何人都可以幫我理解執行嗎? 我怎麼能隱藏列表分隔符爲少數列表項目,而其他人有它?

問候,

拉詹

+0

使用與不同的佈局列表視圖每一行。製作一些行分隔符:http://stackoverflow.com/questions/4777272/android-listview-with-different-layout-for-each-row – VM4 2014-10-19 10:49:28

回答

1

對於每個列表項的行使用此佈局:

<LinearLayout> 
    (...) 
    <View 
    android:id="@+id/viewSeparator1" 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="#646464"/> 
</LinearLayout> 

然後在您的適配器使用本

public class DrawerListAdapter extends BaseAdapter{ 

    (...) 

    public View getView(int position, View convertView, ViewGroup parent){ 
     (...) 
     View mViewSeparator = convertView.findViewByID(R.id.viewSeparator1); 

     //I dont know when you want to show a separator so replace this line with the apropriate check: for example: if(position == 0) etc 
     if(hasSeparator) 
      mViewSeparator.setVisibility(View.VISIBLE); 
     else 
      mViewSeparator.setVisibility(View.GONE); 

     return convertView; 
    } 
} 
+0

不要忘記從列表視圖中刪除默認分隔符,因爲您提供了一個分隔符每行: 使用:android:divider =「@ null」or yourListView.setDivider(null); – nunoh123 2014-10-19 12:16:00

+0

感謝您的回覆。但我無法得到如何評估每個列表項目。目前,我正在使用適配器,如'代碼'\t \t adapter = new DrawerListAdapter(getApplicationContext(),navDrawerItems); \t \t mDrawerList.setAdapter(adapter);'code'。我如何在我的情況下應用上面的代碼。 – 2014-10-19 13:52:41

+0

編輯答案:我給你的代碼需要在你的自定義適配器類裏的getView裏面。 – nunoh123 2014-10-19 14:21:04