You cannot compare the position and the tag of a previously bound view. Like said before, there's no guarantee that a View previously used at position=X will be reused at the same position. Do not rely on this. At all. As for the convertView == null twice for the same position that's probably because your grid has a height = wrap_content.
On Sun, Feb 28, 2010 at 2:22 PM, marmor <[email protected]> wrote: > Hi, > > I've been experiencing this problem too, > I don't rely on the order in which getView are called, but I do rely > on the position. > I noticed the *position* order (not call order) is reversed when I > turn on the onscreen keyboard, and back again when I exit it. > > I've added a tag to the views i'm creating marking the position in > which they were created and I've printed this tag when convertView is > not null. > > This is what I got for thee objects on the grid: > > count = 3 > pos = 0, conView = null > new: pos = 0, v = ....@43d01ab0 > pos = 0, conView = ....@43d01ab0 > pos = 0, v = ....@43d01ab0, v.tag = 0 > pos = 1, conView = null > new: pos = 1, v = ....@43d0bc70 > pos = 2, conView = null > new: pos = 2, v = ....@43d0e2b8 > pos = 0, conView = null > new: pos = 0, v = ....@43d0a2b8 > pos = 0, conView = ....@43d0e2b8 > <here i opened the onscreen keyboard, notice the pos and tag conflict> > pos = 0, v = ....@43d0e2b8, v.tag = 2 > pos = 1, conView = ....@43d0bc70 > pos = 1, v = ....@43d0bc70, v.tag = 1 > pos = 2, conView = ....@43d01ab0 > pos = 2, v = ....@43d01ab0, v.tag = 0 > pos = 0, conView = ....@43d0a2b8 > <here i closed the onscreen keyboard, pos and tag conflict disappears> > pos = 0, v = ....@43d0a2b8, v.tag = 0 > pos = 0, conView = ....@43d01ab0 > pos = 0, v = ....@43d01ab0, v.tag = 0 > pos = 1, conView = ....@43d0bc70 > pos = 1, v = ....@43d0bc70, v.tag = 1 > pos = 2, conView = ....@43d0e2b8 > pos = 2, v = ....@43d0e2b8, v.tag = 2 > > You can also notice I'm getting conView=null *twice* for position 0, > this is also a problem i think. > > Any ideas? > > Mor. > > On Feb 26, 1:29 am, Bolha <[email protected]> wrote: >> Hi, Streets Of Boston. >> >> I haven't thought about that, maybe because myGridViewshows very few >> elements (like 10 or 20). >> Although seeing the getView method passing or not an instantiated >> view, I didn't realize that it was caching just the visible views. >> >> But how can we fix the sorting problem without doing a manual views >> caching? I've seen that thepositionparameters is informed in order, >> but I have no clue why the View instance doens't correspond to the >> correctposition. >> Oh, just to make it clear, I'm programming on SDK version 2.1 but >> running on a 1.5 device. >> >> Thanks for the help >> >> Bolha >> >> On 24 fev, 17:40, Streets Of Boston <[email protected]> wrote: >> >> >> >> > Thanks! >> >> > But I think you will get serious performance issues on GridViews and >> > ListViews with many items. In your fix, you cache the View for each >> > possible item. This defeats the purpose of the 'convertView' parameter >> > which has a non-null value when theGridViewre-uses a cached View. >> > The amount of Views cached by theGridViewis no more than the amount >> > of (partially) visible items on the screen >> > (=ListView.getChildCount()), not the number of possible items >> > (=BaseAdapter.getCount()), which can be much larger. >> >> > If you BaseApapter can have many items (more items than can be viewed >> > simultaneously on the screen), you'll likely to hit some serious >> > performance/memory/resource issues. >> >> > On Feb 24, 1:12 pm,Bolha<[email protected]> wrote: >> >> > > Hello, guys. >> >> > > I've had the same problem and solved it by saving the created views in >> > > an array inside the adapter. Check the chunks of code below: >> >> > > public class ImageButtonCanalAdapter extendsBaseAdapter{ >> > > private Context contexto; >> > > private List<MyClass> list >> > > private View savedViews[]; >> >> > > [...] >> >> > > public View getView(intposition, View convertView, ViewGroup >> > > parent) >> > > { >> > > if (convertView == null) { >> > > this.viewsBotoes[position] = new MyView >> > > (this.contexto); >> > > } >> >> > > return this.viewsBotoes[position]; >> > > } >> >> > > } >> >> > > I hope it helps. >> >> > > Best regards. >> >> > >Bolha >> >> > > On 20 jan, 00:35, Streets Of Boston <[email protected]> wrote: >> >> > > > The animation is not necessary to make it happen. It just makes it >> > > > really easy to actually see the issue :-) >> >> > > > On Jan 19, 6:06 pm, Mike M <[email protected]> wrote: >> >> > > > > yeah, >> > > > > I get the same on Droid 2.0, Although I get it without having >> > > > > animation applied to thegridview... >> >> > > > > I wish there was a uniform / sequential way that getView() was >> > > > > called... >> >> > > > > On Jan 18, 5:29 pm, Streets Of Boston <[email protected]> >> > > > > wrote: >> >> > > > > > Hi Roman, >> >> > > > > > It does happen. :-) >> >> > > > > > I can reproduce it almost every time like this: >> > > > > > - Just create an activity with a Grid View with quite a few images >> > > > > > (or >> > > > > > grid-items) and attach a grid-layout-animator to the grid-view. >> > > > > > Configure the grid-view-animator in such a way that you see how the >> > > > > > grid-view-items are laid-out. E.g. columns first, rows later. >> > > > > > - Create an (empty) sub-activity that can be launched from the one >> > > > > > having the grid-view. >> >> > > > > > - Start your grid-view's activiy in portrait orientation. >> > > > > > - Start your sub-activity. >> > > > > > - Rotate your phone into landscape orientation. >> > > > > > - Press back to finish the sub-activity. >> > > > > > The grid-view's activity is shown again and... >> >> > > > > > ... 9 out of 10 times, i see the grid-view being built up in >> > > > > > reverse >> > > > > > mode (i'm running on 2.1, Nexus One). >> >> > > > > > In my app, the 'getView()' method does not rely on the order in >> > > > > > which >> > > > > > the 'getView()' is called at all. >> >> > > > > > On Jan 18, 2:15 am, Romain Guy <[email protected]> wrote: >> >> > > > > > > I have never noticed such an issue. The only way I can think of >> > > > > > > that >> > > > > > > would cause this to happen would be if your adapter relies on the >> > > > > > > order of the getView() calls. Note there is absolutely no >> > > > > > > guarantee >> > > > > > > about the order in which getView() will be called (theposition >> > > > > > > argument will not necessarily be sequential, incrementing or >> > > > > > > decrementing.) >> >> > > > > > > On Sun, Jan 17, 2010 at 8:57 PM, Mike M <[email protected]> >> > > > > > > wrote: >> > > > > > > > Streets of Boston, >> >> > > > > > > > Thanks for the reply. I do have an animation on myGridView, >> > > > > > > > but I >> > > > > > > > took it off and still notice the problem. >> >> > > > > > > > Any ideas? >> >> > > > > > > > Thanks >> >> > > > > > > > On Jan 17, 1:23 pm, Streets Of Boston >> > > > > > > > <[email protected]> wrote: >> > > > > > > >> I've seen this too in my app. >> >> > > > > > > >> If you add a layout-animation, that animates the grid-view >> > > > > > > >> children >> > > > > > > >> (i.e. the grid-items), you can clearly see this reverse order. >> >> > > > > > > >> On Jan 17, 4:03 am, Mike M <[email protected]> wrote: >> >> > > > > > > >> > Hey everyone, >> >> > > > > > > >> > I have agridviewof images that I load from the internet. >> > > > > > > >> > When the >> > > > > > > >> > phone rotates (or some other config change), >> > > > > > > >> > onConfigurationChanged() >> > > > > > > >> > is called. When that happens, the items in thegridvieware >> > > > > > > >> > reversed >> > > > > > > >> > (meaning, the 1st image is the last; they are in reverse >> > > > > > > >> > order). >> >> > > > > > > >> > Does anyone know why this is or how to change it? I'm >> > > > > > > >> > hoping someone >> > > > > > > >> > has run into this before... >> >> > > > > > > >> > Sorry if I don't share any code. I don't think It'd help; >> > > > > > > >> > it's more >> > > > > > > >> > of a conceptual question. >> >> > > > > > > >> > Thanks, >> >> > > > > > > >> > Mike >> >> > > > > > > > -- >> > > > > > > > You received this message because you are subscribed to the >> > > > > > > > Google >> > > > > > > > Groups "Android Developers" group. >> > > > > > > > To post to this group, send email to >> > > > > > > > [email protected] >> > > > > > > > To unsubscribe from this group, send email to >> > > > > > > > [email protected] >> > > > > > > > For more options, visit this group at >> > > > > > > >http://groups.google.com/group/android-developers?hl=en >> >> > > > > > > -- >> > > > > > > Romain Guy >> > > > > > > Android framework engineer >> > > > > > > [email protected] >> >> > > > > > > Note: please don't send private questions to me, as I don't have >> > > > > > > time >> > > > > > > to provide private support. All such questions should be posted >> > > > > > > on >> > > > > > > public forums, where I and others can see and answer them- Hide >> > > > > > > quoted text - >> >> > > > > > > - Show quoted text -- Hide quoted text - >> >> > > > > - Show quoted text -- Hide quoted text - >> >> > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

