活动类代码:

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" 

其他回答

在列表视图的自定义行布局中使用下面的代码

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

以上这些对我来说都失败了。然而,我能够解决这个问题(经过几个小时的敲击我的头-谷歌,如果你在听,请考虑修复我在编译器错误的形式,如果可能的话)

你真的需要小心你添加到xml布局的android属性(在这个原始问题中,它被称为list_items.xml)。对我来说,导致问题的原因是我已经从EditText视图切换到TextView,并且从更改中有剩余的属性cruft(在我的情况下,inputType)。编译器没有捕捉到它,当我去运行应用程序时,可点击性刚刚失败。再次检查你在布局xml节点中拥有的所有属性。

我也遇到了同样的问题,尝试了所有提到的解决方案都无济于事。通过测试,我发现使文本可选会阻止侦听器被调用。通过将它切换为false,或者删除它,我的监听器再次被调用。

android:textIsSelectable="false"

希望这能帮助像我这样被困住的人。

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

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

android:descendantFocusability="blocksDescendants"

还不够。你必须设置

android:textIsSelectable="false"

到你的textviews和

android:focusable="false"

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