首页 文章

无法使Listview项目可单击

提问于
浏览
-2

我无法使我的列表视图可点击 . 我已经针对相同类型的问题尝试了所有给定的解决方案,并尝试将focusable和focusableintouchmode值更改为true和false .

单击10/12次按钮后,有时它可以正常工作(即listview中的文本被点击) . 下面是我的xml和java文件 . 我已经附加了logcat的屏幕截图,当我按下它的行号9被点击后超过20次 . enter image description here请帮忙..

Activity_card.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hppc.business.Card">

    <ListView
        android:id="@+id/lvUsers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:clickable="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:descendantFocusability="blocksDescendants">

    </ListView>

</RelativeLayout>

entry1.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:orientation="horizontal"
    android:padding="13dp">

    <ImageView
        android:layout_width="90dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:src="@drawable/image" />

    <linearlayout>.....</linearlayout>
</linearLayout>

card.java

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {
        Intent i = new Intent(Card.this, Manual.class);
        Log.i("HelloListView", "You clicked Item: " + id + " at position:" + position);
        Log.e("YESSSS",Integer.toString(position));
        startActivity(i);
    }
});

1 回答

  • 0

    你必须让你的列表视图可以集中:

    android:focusable="true"
               android:focusableInTouchMode="true"
    

相关问题