Hi,
I am trying to use a GridView control to display a list of user defined controls.
I created my own adapter to which I manually added 20 items, like this:
for (int i = 0; i < 20; i++) {
MyControl item = new MyControl(this);
item.setText("hello " + i);
myadapter.addItem(item);
}
gridview.setAdapter(myadapter);
What i expected to see on the screen was a list of items with the texts "hello 0", "hello 1", ... "hello 19".
The actual result was something like: "hello 0", "hello 1", "hello 2", "hello 3", "hello 4", and then repeating from "hello 0", to a total of 20 items.
I tried debugging the method getView in my adapter:
@Override
public View getView(int position, View view, ViewGroup parent)
At first, the position parameter was 0, then incremented to 1, and after 4 it came back to 0. Why is that?
I also tried using ListView instead of GridView and I got a similar result, except the order of the items was also messed up, not even the 0-4 interval was sorted.
Has anyone experienced this before? Am I missing something? I think it might have something to do with scrolling.
Thank you
I am trying to use a GridView control to display a list of user defined controls.
I created my own adapter to which I manually added 20 items, like this:
for (int i = 0; i < 20; i++) {
MyControl item = new MyControl(this);
item.setText("hello " + i);
myadapter.addItem(item);
}
gridview.setAdapter(myadapter);
What i expected to see on the screen was a list of items with the texts "hello 0", "hello 1", ... "hello 19".
The actual result was something like: "hello 0", "hello 1", "hello 2", "hello 3", "hello 4", and then repeating from "hello 0", to a total of 20 items.
I tried debugging the method getView in my adapter:
@Override
public View getView(int position, View view, ViewGroup parent)
At first, the position parameter was 0, then incremented to 1, and after 4 it came back to 0. Why is that?
I also tried using ListView instead of GridView and I got a similar result, except the order of the items was also messed up, not even the 0-4 interval was sorted.
Has anyone experienced this before? Am I missing something? I think it might have something to do with scrolling.
Thank you