单击不适用于 Listitem Listview android [英] Click is not working on the Listitem Listview android

查看:20
本文介绍了单击不适用于 Listitem Listview android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ListActivity 实现了 android listview.在这里,我遇到的问题是,当我单击列表项时,当闪光灯颜色也没有出现橙色时,不会执行任何操作.那么你对我的问题的这个友好回答有什么想法吗?

I implemented the android listview with the ListActivity. Here I have the problem that when i click on the list item no action is performed when the flash color is also not coming that is the orange color. So do you have any idea about this kindly answer to my question.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) 
{
    super.onListItemClick(l, v, position, id);
    Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_SHORT)
            .show();

}

我也把这段代码放到了 Main ListActivity 中.

I put this code also into the Main ListActivity.

推荐答案

首先要注意的是,只要 中存在可点击的元素,例如 Buttons 或 ImageButtonsListView 元素,它们控制点击事件.所以你的 ListView 不会有机会接受点击事件.

The first thing what you have to note here is, whenever there are Clickable elements like Buttons or ImageButtons present in your ListView element, they take the control of click events. And so your ListView won't get the chance to accept the click event.

您只需要做的是,将 ListView 中的 ButtonImageButtonfocusable 属性设置为 false.但是它们仍然可以正常工作,并且您的 ListView 的 onListItemClick 也可以工作.

What you simply have to do is, set the focusable attribute to false for the Button or ImageButton you have in your ListView. But still they will work without any problem and also your ListView's onListItemClick will also work.

试试这个,

        <Button  android:id="@+id/textsize_increaser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/back_button"
        android:focusable="false"
        android:text=" A + "/>

在这里我添加了这个 android:focusable="false" 并且它工作正常.试试吧.

Here I have added this android:focusable="false" and it works fine. try it.

这篇关于单击不适用于 Listitem Listview android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆