2016-03-04 53 views
0

我有导航抽屉XML布局如下,列表视图点击不工作的抽屉式导航

<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"> 

    <ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="180dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/black" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:descendantFocusability="afterDescendants" 
     android:focusable="false" 
     android:focusableInTouchMode="true" /> 

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.v4.widget.DrawerLayout> 

进出口设置onItemClickLister如下,

mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       Toast.makeText(getApplicationContext(),"sd",Toast.LENGTH_SHORT).show(); 
      } 
     }); 

但导航抽屉的onItemClickListener仍未被解雇。

+0

还是一样的问题仍然存在 –

+0

IM下面这个例子https://trinitytuts.com/navigation-drawer-with-tabview-in-android/ –

+1

机器人:descendantFocusability =“blocksDescendants您drawer_item.xml – saeed

回答

1

试图消除android:descendantFocusability="afterDescendants"。因为这个属性,ListView只有当它的后代都不需要时才会关注。另外删除,android:focusable="false"使ListView可重点。

使抽屉的ListViewDrawerLayout的第二个也是最后一个元素。 Demo来自开发人员文档。

<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"> 

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="180dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/black" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:focusableInTouchMode="true" /> 

</android.support.v4.widget.DrawerLayout> 
+0

仍然存在相同的问题 –

+0

即时消息本例下面trinitytuts.com/navigation-drawer-with-tabview-in-android –

+0

@Stanly发布您的活动 –

1

我知道这可能违背你的问题,但我建议你使用导航提示与支持设计。那里你可以添加导航项目,并且还可以添加headerview。

它将根据android设计指南具有默认填充。

这里完成tutorial