ListView控件无法点击,在所有行小部件的TextView [英] ListView is not clickable, all widgets in rows are TextView

查看:122
本文介绍了ListView控件无法点击,在所有行小部件的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的行模式,在一个片段一个ListView; ListView中被正确填充,所有正确的尺寸,颜色等问题是,点击某一行没有触发事件。

I have a simple row model and a ListView in a Fragment; the ListView gets properly populated, with all the correct dimensions, colors, etc. Problem is, clicking on a row fires no event.

在我的片段code是:

The code in my fragment is:

MyAdapter mAdapter = new MyAdapter(getActivity().getApplicationContext(), R.layout.list_row, strings);
mList.setAdapter(mAdapter);

mList.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Log.d("LIST", "Selected item # " + position);
    }
}); 

片段布局(一块吧)是:

The fragment layout (a piece of it) is:

<ListView
    android:id="@+id/m_list"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_margin="20dp"
    android:clickable="true"
    android:longClickable="true">
</ListView>

该行布局是:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent">

    <TextView
        android:id="@+id/txt_surname"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:text="@string/surname"
        style="@style/ListStyleXLarge"/>

    <!-- 4 more TextView just as the first one -->
</LinearLayout>

风格很简单:

    <style name="ListStyleXLarge">
    <item name="android:textSize">
        @dimen/text_size_large
    </item>
    <item name="android:textStyle">
        bold
    </item>
    <item name="android:textColor">
        @color/list_item_text_color
    </item>
</style>

有什么可以解决这个问题?我已经尝试设置

What can fix this problem? I have already tried to set the

android:clickable="false"
android:focuseable="false"
android:focuseableInTouchMode="false"

所有TextViews的,但没有那么远。

to all of the TextViews, but nothing so far.

推荐答案

在您MyAdapter类:

In your MyAdapter class:

在getView方法使用:

In the getView method use:

convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Log.d("LIST", "Selected item # " + position);

            }
        });

这篇关于ListView控件无法点击,在所有行小部件的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆