2

I need to make a custom ListView with multiple view types. I found this link: http://umakantpatil.com/posts/android-listview-with-separate-headers-and-images-loading-from-remote-server But the problem is: It divides the list into sections and creates a single view type. My first question is: How can I modify this code so that I could retrieve my each row with a different type? I mean I want to have a section but I want the items come in a different manner.

My second question is: How can I do that? I thought of two adapters: one to hold a raw view type and one to hold another to set for my listview. How can I that?

Thanks

ikbal
  • 1,844
  • 4
  • 26
  • 46

1 Answers1

2

If I understood what you're trying to accomplish, then I believe I may be able to help you. See here.

When it comes to custom adapters (headered lists, custom-mixed lists etc.), the easier solution in my opinion is SeparatedListAdapter by Jeff Sharkey. By easier I mean "the least amount of code to implement". You may run into problems because that code is GPL'ed v3.

I achieved an excellent solution implementing cwac-merge by CommonsWare. It's ASL 2, so you're good to go if you're thinking about Android market. You can add any adapter, as well as Views directly. It's very, very good. I really recommend it.

You can check more details in my question. If you have any doubt about how to implement, post here and I will try to help.

And by the way, try to improve your record by going into your profile and accepting the answers provided to your questions (in case they actually helped you).

Community
  • 1
  • 1
davidcesarino
  • 16,160
  • 16
  • 68
  • 109
  • Thanks bro but actually I m not a very professional person so your answer seemed a little complicated to me, I downloaded and run Jeff Sharkey code as well as cwac-merge. But it showed me a demo with a some sections and regular rows. I don't know if it can help me but in this case it will be out of my control. I think I don't need that complex solution. – ikbal Jun 14 '11 at 14:17
  • This is actually what I need: I determine what a row view type in runtime and in a loop I want to set an adapter for each row. Thus in my raw adapter I want to change my views. But I can only set one adapter to a listview. So I need to find soemthing that holds a list of adapters instead of one – ikbal Jun 14 '11 at 14:17
  • Don't worry, I'm not a pro either. I know what you want. I know you can't set more than one adapter to a listview. The two solutions above answer exactly that. What didn't you understand exactly? Did you integrate those classes to your source? Did you even try the example code? – davidcesarino Jun 14 '11 at 17:58
  • Remember that you don't need to change anything at all in the adapter classes (those that implement the adapters), like SeparatedListAdapter (J. Sharkey example) or MergeAdapter (in CommonsWare example). The only thing you need to change is the example code. And they are quite easy to implement and change. You really just need to copy and paste, but that assumes you already have the adapters for each kind of row you need. – davidcesarino Jun 14 '11 at 18:35
  • The only other "simple" solution would be to create a simple layout for all rows, and hide/show the views depending on the data provided to the adapter. However, I *really* recommend you not to do that. It's cumbersome, not flexible at all and you WILL regret taking that road. To do that you create signaling data in the HashMap and Arrays (that won't be used to display data, just signal the adapter), and code your adapter to hide/view this and that view as needed. But as I said, don't do that. Try the solutions I gave you first. – davidcesarino Jun 14 '11 at 18:38
  • Another comment: if what you want is to display different adapters for different kind of views, then you can create a different adapter for each row (as you normally do for single-adapter-type lists) and stitch them together using the solution I gave to you. – davidcesarino Oct 05 '11 at 22:36