活动类代码:

conversationList = (ListView)findViewById(android.R.id.list);
ConversationArrayAdapter conversationArrayAdapter=new  ConversationArrayAdapter(this, R.layout.conversation_list_item_format_left, conversationDetails);
conversationList.setAdapter(conversationArrayAdapter);
conversationList.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
        Log.d("test","clicked");
    }
});

Adapter类中的getView函数:

if (v == null) {                                
    LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if(leftSideMessageNumber.equals(m.getTo())) {
        v = vi.inflate(R.layout.conversation_list_item_format_left, null);
    } else {
        v = vi.inflate(R.layout.conversation_list_item_format_right, null);
    }
}

在膨胀时使用两个xml会有问题吗?


当前回答

我也有同样的问题,我在行布局中使用了具有“可聚焦”属性的文本样式。我把它取下来后它还能用。

其他回答

onClick也有同样的问题。解决方案是从xml中删除以下内容

android:tooltipText=""

即使我有同样的问题,我有复选框,做下面的掩码itemClickListener工作,

在复选框中添加以下属性,

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

ItemClickListner开始工作。

详细的例子你可以点击链接,

http://knowledge-cess.com/android-itemclicklistner-with-checkbox-or-radiobutton/

希望能有所帮助,干杯!!

对我有用的是将下面的代码添加到我的row.xml文件布局中的每个子视图中:

android:focusable="false"
android:focusableInTouchMode="false"

在我的例子中:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:id="@+id/testingId"
        android:text="Name"
       //other stuff 
        />

    <TextView
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:id="@+id/dummyId"
        android:text="icon"
        //other stuff 
        />

    <TextView
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:id="@+id/assignmentColor"
       //other stuff 
       />

    <TextView
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:id="@+id/testID"
        //other stuff 
        />

    <TextView
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="TextView"
        //other stuff 
        />

</android.support.constraint.ConstraintLayout>

这是我在Fragment子类中的setOnItemClickListener调用:

CustomListView = (PullToRefreshListCustomView) layout.findViewById(getListResourceID());
        CustomListView.setAdapter(customAdapter);
        CustomListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d("Testing", "onitem click working");
              //  other code
            }

        });

我从这里得到了答案!

我通过从列表中删除可点击的视图来解决这个问题。

问题是你的布局包含可聚焦或可点击的项目。 如果视图包含可聚焦或可点击的项,OnItemCLickListener将不会被调用。

点击这里了解更多信息。

如果不是这样的话,请发布一个你的布局xml。