나는 손실에 처해 있습니다. 조각에서 어댑터를 통해 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"/>
나는 여전히 주사위
'if (null! = mCallback) {}'이 줄에'mCallBack'이란 무엇입니까? –
mCallback = (OnFragmentInteractionListener) activity; 프래그먼트를 호스팅하는 활동으로 되돌아가는 링크입니다. – aobrazcova
ListView 레이아웃이 어떻게 작동하는지 오해했습니다. 사용자 지정 목록을 만들려면이 기본 목록을 수정해야한다고 생각했습니다. 목록 항목에 대한 맞춤 레이아웃을 만들어 맞춤 어댑터에서이를 팽창시켜야합니다 ... – aobrazcova