0

탐색 창에서 ListView를 사용하고 있습니다. 모든 것이 잘 작동했지만 최근에는 코드 일부를 건드리지 않았을 때 클릭 이벤트를 처리하지 않습니다. onItemClick에 중단 점을 배치했지만 결코 그 행에 도달하지 않습니다. ListView가 항목 클릭을 처리하지 않습니다.

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="40sp" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:textColor="#fff" 
     android:textSize="20sp" 
     android:focusable="false" 
    /> 

여러분의 도움에 감사드립니다 : 이것은 "drawer_list_item.xml는"

private void initializeDrawer(){ 

    ... 

    String[] mDrawerMenu = {"Option1", "Option2", "Option3"}; 

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

} 

private class DrawerItemClickListener implements ListView.OnItemClickListener { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
     Toast toast = Toast.makeText(context, "Click on Option " + position, Toast.LENGTH_LONG); 
     toast.show(); 
    } 
} 

입니다 :

내 코드입니다.

+0

단추와 같은 포커스 가능보기를 행 레이아웃에 추가 했습니까? 이 토론은 도움이 될 수 있습니다 : http://stackoverflow.com/questions/8955270/listview-items-are-not-clickable-why – wkarl

+0

@iguarna - 방금 당신의 목록보기가 있는지 확인하십시오. 부모/성냥 부모를 채우기 위해 설정됩니다. 그렇지 않으면 클릭 이벤트가 전체 항목이 아닌 텍스트보기로만 제한됩니다. – Manish

답변

0

내 탐색 창 레이아웃에 "주 콘텐츠보기"가 누락되었음을 깨달았습니다. 그게 어떻게 관련이 있는지는 잘 모르겠지만 문제가 해결되었습니다.

<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 THIS WAS MISSING--> 

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/frame_container"> 

    </FrameLayout> 

    <!-- 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> 
관련 문제