Get Control On List Events
Next, we need to detect when the user clicks on one of our restaurants in the list, so we can update our detail form with that information.
First, add an import for android.widget.AdapterView to LunchList. Then, create an AdapterView.OnItemClickListener named onListClick:
private AdapterView.OnItemClickListener onListClick=new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position,
long id) {
}
};
Finally, call setOnItemClickListener() on the ListView in the activity's onCreate() to connect the ListView to the onListClick listener object (list.setOnItemClickListener(onListClick);)
First, add an import for android.widget.AdapterView to LunchList. Then, create an AdapterView.OnItemClickListener named onListClick:
private AdapterView.OnItemClickListener onListClick=new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position,
long id) {
}
};
Finally, call setOnItemClickListener() on the ListView in the activity's onCreate() to connect the ListView to the onListClick listener object (list.setOnItemClickListener(onListClick);)
No comments:
Post a Comment