OnItemClickListener一个片段里面一个ListView不工作 [英] OnItemClickListener on a ListView inside a Fragment not working

查看:137
本文介绍了OnItemClickListener一个片段里面一个ListView不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:解决。如果有什么可聚焦在项目的XML,这将打破触摸名单,换句话说,机器人:可聚焦= false将所有的复选框,开关之类的东西乌尔名单。而做=)

好了,所以,这里是我的问题。

我写了一个使用标签和片段一个应用程序,这一切都我想除了东西的方式,当我尝试捕捉onItemClick上一个ListView 它甚至不标记行作为触及/ pressed /选择。

我一直在阅读有关一点点,很多人也有同样的问题,但我没有发现任何方式帮助任何答复我。

我不想要实现一个ListFragment,其实我甚至不知道如何/为什么我要,因为所有我的code已经工作,我不知道,如果实现一个给我更多的工作要做,所以,在这里它是:

是否有可能实现一个监听器的点击列表视图,片段里面?如果是,怎么了?

PD:minSDK = 14,tatgetSDK = 15

解决方案

这里的code片段,会做你想要什么。

 的ListView LV;

// code以获得使用findViewByID等ListView控件实例

lv.setOnItemClickListener(新OnItemClickListener()
{
    @覆盖公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长ARG3)
    {
        Toast.makeText(EnclosingActivity.this,停止点击我,Toast.LENGTH_SHORT).show();
    }
});
 


人们通常跳闸这一点,看看你有没有这种覆盖:

所有的点击和回调(如:菜单/动作条回调)发送到片段结合的活动,所以他们必须在活动类,而不是片段类

EDIT: SOLVED. If there's anything focusable in the XML of the items, it will break the touch of the list, in other words, android:focusable=false to all the checkboxes, switches or anything like that of ur list. And done =)

Ok so, here's my problem.

I wrote a app that uses tabs and fragments, and it all goes the way I want except for the thing that when I try to capture a onItemClick on a listView it does not even mark the row as touched/pressed/selected.

I've been reading a little bit about and many people have the same issue, but I did not found any responses that helped me at all.

I don't want to implement a ListFragment, in fact I don't even know how/why I should, and since all my code is already working, I don't know if implementing one will give me much more work to do, so, here it is:

Is it possible to implement a listener for a click on a listView, inside a fragment? and if it is, HOW?

PD: minSDK=14, tatgetSDK=15

解决方案

Here's a code snippet that'll do what you want.

ListView lv;

//code to get the listView instance using findViewByID etc

lv.setOnItemClickListener(new OnItemClickListener()
{
    @Override public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
    { 
        Toast.makeText(EnclosingActivity.this, "Stop Clicking me", Toast.LENGTH_SHORT).show();
    }
});


People usually trip on this, see if you have got this covered:

All clicks and call backs (eg: the menu/actionbar callbacks) are sent to the activity the fragment is bound to, so they must be in the activity class and not the fragment class.

这篇关于OnItemClickListener一个片段里面一个ListView不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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