活动类代码:

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


当前回答

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

android:clickable="true"

其他回答

我借助这个答案解决了它

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

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

 android:focusable="false" 

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

对于我的列表,我的行有其他可以点击的东西,比如按钮,所以做一个毯子blocksDescendants是行不通的。相反,我在按钮的xml中添加了一行:

    android:focusable="false"

这样可以防止按钮阻塞对行的单击,但仍然允许按钮接受单击。

Android:autoText属性也使TextView可自动聚焦。

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

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