2014-09-10 1 views
0

나는 손실에 처해 있습니다. 조각에서 어댑터를 통해 ListView를 설정했습니다.ListView OnItemClickListener가 실행되지 않습니다.

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_knowledgebase, container, false); 

    // Set the adapter 
    mListView = (AbsListView) view.findViewById(R.id.searchResultList); 


    // Set OnItemClickListener so we can be notified on item clicks 
    mListView.setOnItemClickListener(this); 
    mListView.setAdapter(mAdapter); 

    return view; 
} 


public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
    if (null != mCallback) { 
     //call back to activity 
     mCallback.onFragmentInteraction(position); 
    } 
} 

목록의 레이아웃은 간단합니다. 단 1 개의 텍스트보기, 버튼 또는 확인란이 없습니다.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ListView 
    android:id="@+id/searchResultList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:footerDividersEnabled="true" 
    android:clickable="true" 
    /> 

<TextView 
    android:id="@+id/name" 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:gravity="start" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:clickable="false" 
    android:textIsSelectable="false"/> 

나는 여전히 주사위

+1

'if (null! = mCallback) {}'이 줄에'mCallBack'이란 무엇입니까? –

+0

mCallback = (OnFragmentInteractionListener) activity; 프래그먼트를 호스팅하는 활동으로 되돌아가는 링크입니다. – aobrazcova

+0

ListView 레이아웃이 어떻게 작동하는지 오해했습니다. 사용자 지정 목록을 만들려면이 기본 목록을 수정해야한다고 생각했습니다. 목록 항목에 대한 맞춤 레이아웃을 만들어 맞춤 어댑터에서이를 팽창시켜야합니다 ... – aobrazcova

답변

0

당신의 변수 mCallback가 null입니다 주요 문제를 false로 포커스 속성을 설정하지 않고했습니다.

public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
    Log.e("ListView OnItemClick","Clicked"); 
    if (null != mCallback) { 
    //call back to activity 
    mCallback.onFragmentInteraction(position); 
    } 
} 

를 기록합니다 : 그래서 아래의 코드는

public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
    if (null != mCallback) { 
    //call back to activity 
    mCallback.onFragmentInteraction(position); 
    } 
} 

이 거의이

if (null != null) { 

내 대답을 확인,이 시도는 ... 실행되지 않고있는 상태입니다 ListView OnItemClick Clicked

+0

해당하지 않습니다. ididnt는 이전에 문제가되었던 모든 코드를 복사하지만 mCallback은 onAttach (activity 활동)에서 공개 무효로 설정됩니다. { super.onAttach (activity); 시도 { mCallback = (OnFragmentInteractionListener) activity; } } 나는 계속해서 어쨌든 솔루션을 시도했지만 여전히 트리거하지 않습니다. – aobrazcova

+0

는 '<텍스트 뷰는 로이드 : ID = "@ + ID/이름" 로이드 : layout_width = "match_parent" 로이드 : layout_height은 = "40dp" 로이드 중력 = 로이드 "시작"포커스 = "FALSE" 안드로이드 : focusableInTouchMode = "false" android : clickable = "false" android : textIsSelectable = "false"/> ' 이 목록보기 행 항목입니까? –

+0

예. 그것은 간단합니다. – aobrazcova

0

어쩌면 그것은 있어야한다 onListItemClick

@Override 
public void onListItemClick(ListView l, View v, int position, long id) { 
관련 문제