Hi
Sorry, I think I misunderstand you last post. Which of the two
methods is the 'old' one (with the 'random order' problem) and which
is the 'new' one (where the problem has gone away)?
I would assume that the new/correct version is this one?:
public View getView(int position, View convertView, ViewGroup
parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item,
null);
viewHolder = new ViewHolder();
viewHolder.myView = (MyView)
convertView.findViewById(R.id.myview);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.myView.setText(objects[position]); // <-- THIS IS
THE NEW LINE
return convertView;
}
On Sep 8, 4:18 am, "rious.delie" <[email protected]> wrote:
> Okay, great, you are right, james..
>
> there is something wrong on the getView implementation, still not sure
> why, but my problem is solved by, something like this:
>
> @Override
> publicViewgetView(int position,ViewconvertView, ViewGroup
> parent) {
> ViewHolder viewHolder;
> if (convertView == null) {
> convertView = mInflater.inflate(R.layout.list_item, null);
> viewHolder = new ViewHolder();
> viewHolder.myView = (MyView)
> convertView.findViewById(R.id.myview);
> convertView.setTag(viewHolder);
> } else {
> viewHolder = (ViewHolder) convertView.getTag();
> }
>
> viewHolder.myView.setText(objects[position]);
>
> return convertView;
> }
>
> changed to:
>
> @Override
> publicViewgetView(int position,ViewconvertView, ViewGroup
> parent) {
> ViewHolder viewHolder;
> if (convertView == null) {
> convertView = mInflater.inflate(R.layout.list_item, null);
> viewHolder = new ViewHolder();
> viewHolder.myView = (MyView)
> convertView.findViewById(R.id.myview);
> viewHolder.myView.setText(objects[position]);
> convertView.setTag(viewHolder);
> } else {
> viewHolder = (ViewHolder) convertView.getTag();
> }
>
> return convertView;
> }
>
> On Sep 7, 2:03 pm, jamesc <[email protected]> wrote:
>
>
>
> > Hi
>
> > 1) I'm still not sure why you're doing the measuring yourself (as I'd
> > use a layout xml file to declare thelistitem'sView, and then
> > inflate it/set the values in the adapter's getView() call.
> > 2) I'm guessing that since you are using an adapter and theview
> > holder, that there's an issue with how your getView() method is
> > implemented (or perhaps another implementation of an adapter method).
> > That is, as you know theviewholder allows object reuse; that doesn't
> > mean to say that the object that you're re-using has the correct
> > values in it. It's only there to avoid the expensive inflation/
> > construction; after that point you're expected to set the values in
> > that object (for thelistitem) as per the data in the array/list/
> > structure that is backing the adapter.
>
> > On Sep 7, 3:55 am, "rious.delie" <[email protected]> wrote:
>
> > > thank you,
>
> > > 1) yes, it is anitemon alistview, i populate some numbers of it on
> > > alistview.
> > > 2) i need to set the height of theviewon runtime, because the height
> > > of theviewis the variable of width (height = f(width)),
> > > it is just as simple as the TextView, which can determine how many
> > > lines needed to show the text based on a function of display width,
> > > each font width, and the text to be displayed.
> > > Yes, i have implemented an adapter (an extends of ArrayAdapter) and
> > > have used ViewHolder (static class ViewHolder()),
>
> > > my point is, why bitmap1changesorderrandomlywhilebitmap2 stays
> > > where it should be,
>
> > > something like this:
>
> > > alistview=
>
> > > view1 = bitmap1 = "hai i am bitmap1 in view1"
> > > bitmap2 = "hai i am bitmap2 in view1"
>
> > > view2 = bitmap1 = "hai i am bitmap1 in view2"
> > > bitmap2 = "hai i am bitmap2 in view2"
>
> > > view3 = bitmap1 = "hai i am bitmap1 in view3"
> > > bitmap2 = "hai i am bitmap2 in view3"
>
> > > view4 = bitmap1 = "hai i am bitmap1 in view4"
> > > bitmap2 = "hai i am bitmap2 in view4"
>
> > > view5 = bitmap1 = "hai i am bitmap1 in view5"
> > > bitmap2 = "hai i am bitmap2 in view5"
>
> > > i scroll fastly, then theorderof bitmap1changes:
>
> > > view1 = bitmap1 = "hai i am bitmap1 in view4"
> > > bitmap2 = "hai i am bitmap2 in view1"
>
> > > view2 = bitmap1 = "hai i am bitmap1 in view5"
> > > bitmap2 = "hai i am bitmap2 in view2"
>
> > > view3 = bitmap1 = "hai i am bitmap1 in view2"
> > > bitmap2 = "hai i am bitmap2 in view3"
>
> > > view4 = bitmap1 = "hai i am bitmap1 in view1"
> > > bitmap2 = "hai i am bitmap2 in view4"
>
> > > view5 = bitmap1 = "hai i am bitmap1 in view3"
> > > bitmap2 = "hai i am bitmap2 in view5"
>
> > > moreover, theorderrandomchangesappearwhilei scroll thelistview
> > > fastly, if i gently scroll it slowly the problem is not occured, it
> > > seems that the problem is not on the code, (is it a bug on android
> > > platform?)
>
> > > On Sep 6, 2:17 pm, jamesc <[email protected]> wrote:
>
> > > > OK. I've had a quick look.
>
> > > > 1) I take it that yourView(MyView) is theitemin theListView?
> > > > 2) Why are you doing the measuring (and implementing onDraw())? I
> > > > would have thought that you should be using a layout to declare the
> > > >ListViewitemand then backing that with a BaseAdapter implementation
> > > > (where you should look at using the "viewholder" pattern to allow re-
> > > > use of inflated objects.
>
> > > > On Sep 6, 5:15 am, "rious.delie" <[email protected]> wrote:
>
> > > > > somebody please...
--
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