views:

503

answers:

1

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>

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);
}

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.

+2  A: 

Okay I figured it out.

The onItemSelectedListener listens for selections of the list items. Not for clicks on the list items. A selection in this case could be seen as moving the focus on this item with the trackpad of the device.

To get the wanted behavior I have to use the OnItemClickListener.

Janusz