2014-10-19 131 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