Daniel Storch
Daniel Storch

Reputation: 327

Android ListView with 5 different layouts

I'm new to android and don't know how to make a ListView with more than 1 layout. I need 5 different layouts in the same ListView. The list won't have more than 5 items each with a different layout. Also will there be a problem if one layout is a VideoView?

I don't have any code to post, sins I didn't know where to start.

Thanks in advance!

Upvotes: 0

Views: 90

Answers (2)

If you are using Eclipse, go to the relevant xml layout in the /res/layout folder (for MainActivity.java it might be activity_main.xml). From here you can add views/layouts inside your ListView by dragging them onto the ListView in the 'stucture' window to the right of your screen.
They will be in the order you place them, top to bottom.

You can get your viewslayouts from the widgets panel or add them programatically in Java (do this in the corresponding Java file).

Alternatively, you can write your views/layouts in using xml, make sure they are between the ListView tags so it contains them.

Upvotes: 0

An SO User
An SO User

Reputation: 24998

You need to override the getViewTypeCount() and getItemViewType() in your adapter.

The getViewTypeCount() would return 5 and getItemViewType() would determine what type of view (out of the 5) is to be displayed.

Upvotes: 1

Related Questions