I read all the other posts on getView() and didn't find any solutions. I have a GridView with a SimpleCursorAdapter. I log(position); in getView() and I see a pattern like this:
0,0,1,0,0,2,0,0,3,0,0,4,0,0,5 etc. This means I'm having to build 3 views as it scrolls for every new view displayed and it's choppy and laggy. Why does it do this? I don't have anything obvious like setting my gridview to wrap-content or anything else weird. There's nothing strange about my code. One thing that might be a factor is that every item view could have a different height depending on the length of the text I'm displaying.
I'm currently debugging on a 4.2.2 Galaxy Nexus.
Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
OnItemClickListener MshowforItem = new AdapterView. OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((TextView)view). setText("Hello"); } };
Index 0 is requested in gridview measure/layout pass.
The question doesn't have the details, but the following could explain the pattern you're seeing:
The GridView
is in a layout that requires two measure/layout passes (e.g. LinearLayout
with weights, RelativeLayout
with layout dependency rules). This explains the two position 0s.
Each getView()
causes the parent to re-layout. This explains the position 0 after each position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With