2017-06-26 109 views
-2

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

点击按钮10/12次后,它有时会工作(即listview中的文本被点击)。 下面是我的xml和java文件。 我已经附上了logcat的截图,当我按了20多次后,我的第9行被点击了。 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

尝试删除'机器人:可点击=“真”'你entry1.xml –

+0

从你的列表视图中删除XML的最后四行即。可点击的,可调焦的,可调焦的touchmode,特别是后裔可聚焦性 –

+0

@JozefDochan非常感谢。它的工作 –

回答

0

你必须让你的列表视图可聚焦:

  android:focusable="true" 
      android:focusableInTouchMode="true" 
+0

感谢您的帮助man.I以前已经尝试过,但它没有为我工作。在entry1.xml中删除可点击。 –