为什么我的onItemSelectedListener不叫在ListView? [英] Why is my onItemSelectedListener not called in a ListView?

查看:168
本文介绍了为什么我的onItemSelectedListener不叫在ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个ListView就是建立这样的:

I'm using a ListView that is setup like this:

<ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:longClickable="false"
    android:choiceMode="singleChoice">
</ListView>

在我的code我添加OnItemSelectedListener到ListView这样的:

In my code I add an OnItemSelectedListener to the ListView like this:

getListView().setAdapter(adapter);
getListView().setOnItemSelectedListener(this);

我的活动实现监听器这样的:

my Activity implements the listener like that:

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    Log.d("Tag", "ListItemSelected: Parent: " + parent.toString() + " View: "
            + view.toString() + " Position: " + " Id: " + id);
}

我的希望是,我会看到这样的调试输出的那一刻我点击的东西在列表中。但是调试输出再也不能在LogCat中所示。

My hope was, that I would see this debug output the moment I click on something in the list. But the debug output is never shown in LogCat.

推荐答案

的<一个href="http://developer.android.com/intl/de/reference/android/widget/AdapterView.OnItemSelectedListener.html"相对=nofollow> onItemSelectedListener 监听列表项selectionsand没有列表项的点击。

The onItemSelectedListener listens for list item selectionsand not list item clicks.

在这种情况下的选择可以看作是移动焦点就这个项目与设备的触控板。

A selection in this case could be seen as moving the focus on this item with the device's trackpad.

要获得想要的行为,必须使用<一个href="http://developer.android.com/intl/de/reference/android/widget/AdapterView.OnItemClickListener.html"相对=nofollow> OnItemClickListener 。

To get the wanted behavior one must use the OnItemClickListener.

这篇关于为什么我的onItemSelectedListener不叫在ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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