android-listview - Android - 抽屉导航适配器

标签 android-listview android-adapter android-navigation

我正在按照以下方式实现抽屉导航:http://developer.android.com/training/implementing-navigation/nav-drawer.html

本教程仅显示 ID 为 android:id="@android:id/text1" 的单个 TextView,并使用以下方法填充 ListView:

mDrawerList.setAdapter(new ArrayAdapter<String>(
            this,
            R.layout.drawer_list_item,
            mDrawerItems));

现在,我想在每个 ListView 项目中包含一个 ImageView。这将代表每个项目的图标。

问题:在列表项的 xml 中(TextView text1 所在的位置),我包含了一个 ImageView。

  1. 我需要什么来命名 ImageView 的 ID?

  2. 然后,我是否只需像这样将可绘制数组引用添加到 setAdapter 中?

    mDrawerList.setAdapter(new ArrayAdapter<String>(
            this,
            R.layout.drawer_list_item,
            mDrawerItems,
            mDrawerIcons));
    

谢谢

最佳答案

我发现创建一个ArrayAdapter上述格式不允许您向 Adapter 输入多于一组的数据。 。例如,我只能使用 Array<String> 中包含的抽屉导航名称列表。 :mDrawerItems。要将图标和其他数据传递给适配器,我有两个选择:

  1. Simple AdapterMap 一起使用,或

  2. 自定义适配器。

两者的示例都可以在这里找到:http://www.vogella.com/articles/AndroidListView/article.html ,这里:

http://www.shenhengbin.wordpress.com/2012/03/17/listview-simpleadapter/

关于android-listview - Android - 抽屉导航适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18540562/

相关文章:

Android SimpleAdapter 错误的数据项与列表行相关联

android - 包含 TabHost 和其他 ListView 的 ListView

java - 在 Activity 之间来回传递数据

android - ListView 布局返回空 View

android - GnssStatus.CallBack onSatelliteStatusChanged() 不工作

android - 我必须在 Android Manifest 中指定父 Activity 名称吗?

android - 具有 1k 对象列表的优化 ListView

android - ContentObserver 可以与新的 RecyclerView notifyItem 函数一起使用吗?

Android/更改特定微调项中的文本

安卓导航 View : Scroll the menu items only issue