2017-09-06 86 views
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); 
+0

请显示您的适配器代码 –

+0

使用回收者视图 –

回答

0

在itemClick在监听器设置 公共无效onItemClick(适配器视图父母,查看查看,int位置,长ID) 用户参数视图,这是查看返回的是点击,而不是使用parent.getView(位置)