tags:

views:

58

answers:

1

Hi,

I have a simple ListView in my layout.xml file.

<ListView android:id="@+id/action_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

And in my javacode, I add a setOnItemClickListener() to my listview:

listView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        System.out.println ("get onItem Click position= "+position);
    }
});

But when I run on G1. I don't see any print out when I click an item on the ListView on the phone. Or when I select an item using track ball and press CENTER.

Can you please tell me why to resolve my problem?

Thanks in advance.

+1  A: 

The click listener is working; the problem is that System.out.println() doesn't work on Android. On Android you use android.util.Log for logging data from the phone. For example, you'd use:

listView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Log.v("MyApp", "get onItem Click position= " + position);
    }
});

Then in Eclipse, you should open up the LogCat view (Window --> show view --> other --> android --> LogCat). Your log should end up there. Alternatively, you can use the ddms tool to view phone logs.

Daniel Lew