setOnItemClickListener赢了工作 - 为什么?

时间:2016-02-22 11:17:35

标签: android listview events mobile listener

我有一个自定义列表视图:

trainingsplan_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
>

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
    android:layout_width="270dp"
    android:layout_height="match_parent"
    android:id="@+id/planinfolinearlayout"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/plannametv"
        android:textColor="@color/darkPrimary"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/trainingszieltv"
        android:layout_below="@+id/plannametv"
        android:textColor="@color/white"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/phasendauerbereichtv"
        android:layout_below="@+id/trainingszieltv"
        android:textColor="@color/white"/>
</LinearLayout>

<ImageButton
    android:layout_width="70dp"
    android:layout_height="wrap_content"
    android:id="@+id/imageButtonInfo"
    android:src="@drawable/informationsmall"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"
    android:layout_toRightOf="@+id/planinfolinearlayout"
    android:background="@color/darkSecondary"
    android:layout_marginTop="5dp"
    android:focusable="false"
    />

</RelativeLayout>

片段:

final ListView planView = (ListView) getActivity().findViewById(R.id.listViewtrainingsplan);
    planView.setItemsCanFocus(false);
    PlanAdapter adapter = new PlanAdapter(getActivity(),R.layout.trainingsplan_item, arrayOfPlans);

    planView.setAdapter(adapter);planView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            changeFocus(planView, position);
        }
    });

但是,当我尝试调试时,它不会调用方法changeFocus。 我试过这个网站上显示的几个解决方案,但没有一个对我有用,有什么想法吗?提前谢谢!

1 个答案:

答案 0 :(得分:2)

删除

planView.setItemsCanFocus(false);