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.
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.
精彩评论