我阅读本教程以创建带有ListView的导航抽屉。 链接:http://developer.android.com/training/implementing-navigation/nav-drawer.html
如何将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>
答案 0 :(得分:0)
答案 1 :(得分:0)
这很漂亮Using multiple layouts in Listview。对于那些想要建立自己的东西的人来说。可以使用Amazing Listview和Expandable Listview