我很茫然。 我有一个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"/>
我已经设置可聚焦的属性设置为false,仍然没有骰子
'如果(空!= mCallback){}'什么'mCallBack'在这一行? – 2014-09-10 16:00:01
mCallback =(OnFragmentInteractionListener)活动;这是一个链接回活动主机片段 – aobrazcova 2014-09-10 16:20:20
原来我误解了ListView布局如何工作。我认为,为了使自定义列表我需要修改这个默认列表。原来我需要为列表项目创建自定义布局,并在自定义适配器中膨胀... – aobrazcova 2014-09-17 17:09:10