Skip to content Skip to sidebar Skip to footer

How Do I Call 2 Consecutive Items In A List In A Table Form Next To Each Other?

Basically I have a list view containing news headlines such that the first headline covers the top portion, the alternate headline the second portion and third headline third porti

Solution 1:

Yes you can use the gridView for this one. here is the example codes

just check link1 and link2

Solution 2:

What this essentially boils down to is finding a compromise between:

  1. A ListView (where you're stuck with individual rows) or GridView (where there are a fixed number of non-spannable columns), or
  2. A fixed layout in the form of a TableLayout or a GridLayout.

Clearly, the first options won't suffice out of the box, because you want some rows with one column and others with two. You may find a compromise in writing your own implementation of a ListView, but this will be extremely tedious and most likely overkill for your application.

I'm aware of a custom component that allows for staggered columns (StaggeredGridView), but you'd instead need column spanning. Perhaps there's another open source custom component out there somewhere that gets this done.

The second option--writing a fixed layout in a TableLayout or a GridLayout--probably won't suit your needs either as the length of your list is dynamic, layouting would be slow, and loading images into the placeholders will consume a considerable amount of memory.

I would instead suggest using a ListView and writing a custom list adapter that inflates different layouts. Those layouts should include ViewGroups that handle the click event instead of having that done through the ListView's own OnItemClickListener. Perhaps you could have two layouts:

  • One headline layout, that is essentially one layout that spans the entire width;
  • One multi-item layout, that displays two news items next to one another with equal weights.

This does mean that you'll need to provide a custom background with selector states and handle the OnClickListener of the individual ViewGroups yourself, but it also allows you to make good use of layouts in for different screen sizes. By using <include> you can consider, for instance, displaying three news items next to each other for res/layout-land or res/layout-w720dp. Perhaps in the case of three columns you could even mix things up a little with a two-column span for articles with image, and single columns for articles without.

Solution 3:

Use grid view. make it auto fit fellow same approach get getItemViewType return large item for first. and rest small. I think this should work, never tried this.

or refer http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-first-item-of.html similar to your problem.

Post a Comment for "How Do I Call 2 Consecutive Items In A List In A Table Form Next To Each Other?"