Android OnItemClickListener在片段中不工作(多列ListView)
我需要你的帮助 我有一个主活动,它包含2个片段(一个用于标题,一个用于多列列表),其中一个片段是ListFragments,它包含一个多列ListView,它被装箱在一个可滚动视图中。此ListFragment重写onItemClickListener方法。我可以滚动视图和所有内容,但当我单击listview时,侦听器不会被调用 我尝试过许多不同的解决方案,比如试图阻止视图的聚焦,但到目前为止没有任何效果。也许你们可以帮我 包含两个片段的父活动:Android OnItemClickListener在片段中不工作(多列ListView),android,android-listview,onclicklistener,android-listfragment,Android,Android Listview,Onclicklistener,Android Listfragment,我需要你的帮助 我有一个主活动,它包含2个片段(一个用于标题,一个用于多列列表),其中一个片段是ListFragments,它包含一个多列ListView,它被装箱在一个可滚动视图中。此ListFragment重写onItemClickListener方法。我可以滚动视图和所有内容,但当我单击listview时,侦听器不会被调用 我尝试过许多不同的解决方案,比如试图阻止视图的聚焦,但到目前为止没有任何效果。也许你们可以帮我 包含两个片段的父活动: <LinearLayout xmlns:a
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:descendantFocusability="blocksDescendants"
tools:context=".MainWindow"
>
<fragment
android:id="@+id/headerfragment"
android:name="lindcom.mobile.estock.fragments.ListHeaderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
/>
<fragment
android:id="@+id/unitlistfragment"
android:name="lindcom.mobile.estock.fragments.UnitsListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
/>
</LinearLayout>
然后,对于点击式侦听器,我只是在片段中覆盖它:
public class UnitsListFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fetch stuff here
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String type = l.getItemAtPosition(position).getClass().toString();
Log.d("Item type was", type);
// THIS IS NEVER INVOKED :(
};
}
我尝试了很多不同的方法,但也许你们可以看到一个简单的解决方法,这是我可能忽略的
任何帮助都将不胜感激!谢谢 在布局中删除您的scollview或将其定义为不可聚焦,然后重试您说您在滚动视图中有一个列表视图吗?是这样吗?如果是这样的话,那就很少是愉快的合作关系,这可能是原因。哇,非常感谢!其实就这么简单。我不明白这是怎么需要的,因为我在scrollView中定义了android:focusable=“false”android:focusableInTouchMode=“false”android:genderantfocusability=“blocksDescendants”,就像在OP中看到的那样。我不敢相信这是那么简单,而且事实证明我可以没有scrollView生活,谢谢!
ListAdapter adapter = new SimpleAdapter(
fragment.getActivity().getBaseContext(), this.unitList,
R.layout.unit_list_item, new String[] { TAG_OWNER, TAG_NAME,
TAG_CONTENT }, new int[] { R.id.unitsCol1, R.id.unitsCol2,
R.id.unitsCol3 });
fragment.setListAdapter(adapter); // Set the adapter to the listFragment
public class UnitsListFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fetch stuff here
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String type = l.getItemAtPosition(position).getClass().toString();
Log.d("Item type was", type);
// THIS IS NEVER INVOKED :(
};
}