0
我遵循Android training以使用侧边栏构建活动。这里是我的xml:Android在抽屉列表中的特定位置获取项目
<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 -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- 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="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
我的问题是:如何获得ListView中的特定位置的视图?我曾尝试一些代码,但没有成功,例如
View firstElement = (View) mDrawerList.getAdapter().getItem(5);
或者在ListView.OnItemClickListener
方法public void onItemClick(AdapterView<?> parent, View view, int position, long id)
我曾尝试:
parent.getChildAt(5);
请显示您的适配器代码 –
使用回收者视图 –