活动类代码:

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会有问题吗?


当前回答

我借助这个答案解决了它

1.在“list_items.xml的线性布局”中添加如下内容 android: descendantFocusability = " blocksDescendants "

2.list_items.xml中线性布局的子视图

 android:focusable="false" 

其他回答

如果你有文本视图,按钮或STG可点击或选择在你的行视图

android:descendantFocusability="blocksDescendants"

还不够。你必须设置

android:textIsSelectable="false"

到你的textviews和

android:focusable="false"

到您的按钮和其他可对焦的项目。

面对同样的问题,试了几个小时。如果你已经尝试了以上所有的,尝试改变Listview的layout_width和列表项的match_parent从wrap_content。

在我的例子中,我必须从布局中删除下一行

android:clickable="true"

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

点击这里了解更多信息。

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

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