0

这是我用于列表的自定义布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:background="@drawable/rounded_corner_5"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:paddingBottom="5dip"
    android:paddingLeft="10dip"
    android:paddingRight="10dip"
    android:paddingTop="5dip" >

    <ImageView
        android:id="@+id/pic"
        android:layout_width="48dip"
        android:layout_height="48dip"
        android:layout_marginRight="5dip"
        android:src="@drawable/icon" />

    <LinearLayout
        android:id="@+id/vert"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/name"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:ellipsize="middle"
                android:singleLine="true"
                android:text="Amit"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:singleLine="true"
                android:text="5 days"
                android:textColor="#333333" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

                <TextView
                    android:id="@+id/currency"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#333333"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/amount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#333333" />

                <ImageView
                    android:id="@+id/direction"
                    android:layout_width="8dip"
                    android:layout_height="8dip"
                    android:layout_marginLeft="5dip"
                    android:src="@drawable/incoming" />

        </LinearLayout>

        <TextView
            android:id="@+id/service"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textColor="#333333" />
    </LinearLayout>

</LinearLayout>

这是我用来处理触发器的活动代码的一部分

list.setItemsCanFocus(false);

        list.setOnItemClickListener(new OnItemClickListener(){
            public void onItemClick(AdapterView<?> v, View view, int position, long itemId){
                Toast.makeText(Home.this, "You selected: " + String.valueOf(position), Toast.LENGTH_SHORT).show();
                SparseBooleanArray sp = list.getCheckedItemPositions();
                if(sp.get(position) == true)
                    view.setSelected(false);
                else
                    view.setSelected(true);
            }
        });

但尽管如此,我还是无法让 Toast 显示出来。我哪里错了?

列表视图的代码是

<LinearLayout 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" >

    <com.markupartist.android.widget.PullToRefreshListView
        android:id="@+id/list"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:divider="@android:color/transparent"
        android:dividerHeight="20.0dip" />

</LinearLayout>
4

1 回答 1

0

I found the issue, I was setting up a onClicklistener on each item, which made it impossible for the list onclick to receive the events.

于 2012-09-04T22:29:56.180 回答