在长按监听ListActivity类 [英] on long click listener ListActivity class

查看:152
本文介绍了在长按监听ListActivity类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它使用的ListView,我已经设置onListItemClick事件查看联系信息,我想实现onLongListItemClick显示一个对话框,我不知道为什么它不工作,我的意思是没有任何反应,我想是这样的:

 公共无效onListItemClick(ListView的父,视图V,INT位置,长ID)
{
    // code
}

公共无效onLongListItemClick(ListView的父,视图V,INT位置,长ID)
{
    的ShowDialog();
}
 

解决方案

尝试这样的:

  listview.setOnItemLongClickListener(新OnItemLongClickListener(){
        @覆盖
        公共布尔onItemLongClick(适配器视图<>为arg0,查看ARG1,
                INT ARG2,长ARG3){
            Toast.makeText(getApplicationContext(),龙浏览次数:次,Toast.LENGTH_LONG).show();
            返回true;
        }
});
 

您需要添加返回true; 这里否则会控制一旦你释放你内心的感动传递到单一的点击事件侦听器

希望它可以帮助你。

感谢。

I have an app which use ListView,I have set onListItemClick event to view details about contact,and I want to implement onLongListItemClick to show a dialog and I don't know why it doesn't work,I mean nothing happens,I tried like this:

public void onListItemClick(ListView parent, View v, int position, long id) 
{   
    //code
}

public void onLongListItemClick(ListView parent, View v, int position, long id) 
{   
    showdialog();
}

解决方案

Try like this :

listview.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            Toast.makeText(getApplicationContext(), "Long Clicked : ", Toast.LENGTH_LONG).show();
            return true;
        }
});

You need to add return true; here otherwise it will transfer control to single click event listener once you release your touch.

Hope it helps you.

Thanks.

这篇关于在长按监听ListActivity类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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