The problem is caused by wrapping the control you're returning from the adapter in a linearlayout. Lose the LinearLayout from your layout file (just put the TextView as the root) and I think it should work.
To expand slighly: you're creating your control, and then adding it into a LinearLayout. At this point a LinearLayout$LayoutParams object is allocated for it and set as its layout params. You then pull it out of the linear layout and put it into your list view, which doesn't understand the LinearLayout$LayoutParams.
Alternatively, return row from getView rather than (as I presume you are doing at the moment, as you have cut the return line out of your quoted code) returning tv.
(Another, unrelated hint: you are inflating your layout and then discarding it when convertView != null; this will result in poor scrolling performance on slow devices. Only perform the inflation if you're actually going to need it.)
yes! it worked.. but as you said, the scrolling is kinda jerky.. how do i smoothen it out without doing inflation? as in how do i get a custom layout for the list without inflating it? and i didnt understand the discarding part.. how is it getting discarded? the uri source of this list is from the mediastore..
Thank you for this @Jules , it helped understanding the issue! Another thing you can do if you still want to use the tv object is to set its layout params to be an instance of AbsListView.LayoutParams, ie: tv.setLayoutParams(new AbsListView.LayoutParams(width, height);
"Alternatively, return row from getView rather than (as I presume you are doing at the moment, as you have cut the return line out of your quoted code) returning tv." That worked like a charm.Thanks.
@TomSusel Thanks for the suggestion worked like a charm ! +1
This answer is misleading. The OP is probably returning tv and not row. If the OP changed the method to return the row then the class cast exception would not occur. There is no reason not wrap the row's TextView in a LinearLayout if that is what you intend.