开发者

Question on custom adapter android

开发者 https://www.devze.com 2023-03-15 15:54 出处:网络
I am a little confused on custom adapters, especially for Gallery.I have a list of objects, say Dogs. Here is the class for Dogs:

I am a little confused on custom adapters, especially for Gallery. I have a list of objects, say Dogs. Here is the class for Dogs:

public st开发者_JAVA百科atic Dogs{
  public string name;
  public string breed;
  public string hometown;
}

What I want my gallery to print out is just the string name value for each element in my Dogs list. How can I do that? I am assuming I would have to do something in my getView method, but I am not sure what to do?? Thanks in advance!


hmm.. make one arraylist that contains object ref of Dogs. Now for each row for list that is 0..n your getview method would be called. you need pass this arraylist to the constructer of your custom adapter. in getsize method you need to pass the size of arraylist. Now when getView will be called automatically ... position of row ie row no is passed automatically. here you will use that postion as index for you arraylist and get the desired Dog object. And then there's a simple substitution of values. Cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消