0

当对列表视图中的项目使用自定义布局时,事实证明 OnItemClickListener 不会触发。

以前,我使用的是 android.R.layout.two_line_list_item。我所做的只是将这个已弃用的布局换成我自己的自定义布局。

我努力了:

-将选择模式设置为单

- 在父列表和列表项中启用长短可点击性

-启用焦点和后代可聚焦性

- 请求焦点

任何反馈将不胜感激!!!

谢谢!

4

3 回答 3

0

这是一些视图项创建代码...

adapter = new ArrayAdapter<ComplexObject>(this, R.layout.item_row, 0,
                al) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null) {
                    convertView = inflater.inflate(R.layout.item_row, parent,
                            false);
                }

                ComplexObject item = adapter.getItem(position);

                ((TextView) convertView.findViewById(R.id.item)).setText(item
                        .getShape());

                ((TextView) convertView.findViewById(R.id.subItem))
                        .setText(item.getWeight() + " lbs");

                ((TextView) convertView.findViewById(R.id.itemSummary))
                        .setText(item.getAge() + " years");

                return convertView;
            }

        };
于 2013-04-19T18:18:29.133 回答
0

我猜你可以尝试在自定义布局的 xml 文件中设置android:clickable="true"。但是您的布局文件的代码可能会更有帮助。

于 2013-04-19T03:43:52.663 回答
0

这是自定义布局...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:focusableInTouchMode="false" >

    <TextView
        android:id="@+id/itemSummary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:textIsSelectable="true" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/itemSummary"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textIsSelectable="true" />

        <TextView
            android:id="@+id/subItem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/item"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textIsSelectable="true" />
    </RelativeLayout>

</RelativeLayout>
于 2013-04-19T18:13:08.473 回答