I have a small application, and I am trying to display list of youtube thumbnails using the ListActivity
public class ResultListActivity extends ListActivity {
.....
......
@Override
protected void onCreate(Bundle savedInstanceState) {
loadData();
---
---
}
private void loadData(final String searchQuery) {
AsyncTask<Object, Void, List<YouTubeVideos>> asyncTask = new AsyncTask<Object, Void, List<YouTubeVideos>>() {
.....
}
/** {@inheritDoc} */
@Override
protected void onListItemClick(ListView l, View v, int pos, long id) {
super.onListItemClick(l, v, pos, id);
Log.d("test","Inside onListItemClick");
}
The xml looks like this
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
</ListView>
<ImageView
android:id="@+id/imageView1"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:focusable="false"
android:focusableInTouchMode="false"
>
</ImageView>
Adapter:
public class ResultViewAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = (ImageView) row.findViewById(R.id.imageView1);
imageView.setImageDrawable(torvideo.getDrawable());
return row;
}
...
}
I am not able to get the onListItemClick invoked. Could you please let me know if I am making any mistake?
Update 1/17
When I click nothing happens but I see these in logs
01-18 04:09:32.030: W/Trace(973): Unexpected value from nativeGetEnabledTags: 0
For ListActivity its simple to call
setOnItemClickListener
The corresponding code is below
You need to add
row.setOnClickListener(new OnItemClickListener(position));
in your ResultViewAdapter for getView()In my
ListView
I have an clickableTextView
and clickableImageView
.onListItemClick
didn't work for me since I have more than one clickable items in the list row. So what I did is i implementedonClickListener
in mygetView()
for the adapter. Here is my code:It happens since we have more than one clickable item and we are trying to use the
ListActivity
. Else the other option is to extendActivity
class for yourMainActivity
and then do it.if you have a class called ListActivity make sure you are extending from the right listActivity because when extending, both your class ListActivity and the super class ListActivity will show up