Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listview with different layout inflation for each row

I'm fairly new to designing UIs in Android (And fairly new to Android development as well). I'm currently developing an Android application that looks a lot like Google+'s "All Circles" page, and Facebook's user home, where you get to see contents shared by your friends.

To make things clearer, please take a look at the following screenshot that's taken from Google+'s Android application:

enter image description here

As you can see, Paul Harper's post is in a little Frame, and "Android and me"'s post is in another. And the more you scroll downwards, the more shared stuff you'll see, each in its own "Frame".

I'm really not sure how to achieve this result(I'm sure that it involves a ListView component), so could anyone please tell me about the UI components that I should be using to do it?

Thanks a ton.

like image 581
Mouhammed Soueidane Avatar asked Mar 29 '13 15:03

Mouhammed Soueidane


2 Answers

You should have a look at the video in the link.

http://www.youtube.com/watch?v=wDBM6wVEO70

private static final int TYPE_ITEM1 = 0;
private static final int TYPE_ITEM2 = 1;
private static final int TYPE_ITEM3 = 2;    

int type;

@Override
public int getItemViewType(int position) {

    if (position== 0){
        type = TYPE_ITEM1;
    } else if  (position == 1){
        type = TYPE_ITEM2;
    }
    return type;
}


@Override  
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = null;
int type = getItemViewType(position);
   if (row  == null) {
    if (type == TYPE_ITEM1) {
                 //infalte layout of type1
      }
    if (type == TYPE_ITEM2) {
                 //infalte layout of type2
    }  else {
                 //infalte layout of normaltype
 }
} 
like image 179
Raghunandan Avatar answered Sep 19 '22 05:09

Raghunandan


You are right. For lists, the keywords you need to look for are "ListView", "ListFragment", "ListActivity". To give your list (items) a custom look, you need to define your own layout for the list rows, which then can contain multiple subviews. To fill your rows (and their subviews) with content you need to define a custom adapter which you set on the list. Look for (e.g.) "ArrayAdapter", "SimpleCursorAdapter".

Try a google search for "android list custom layout" and "android list adapter".

Best regards, Sebastian

like image 37
Sebastian Engel Avatar answered Sep 20 '22 05:09

Sebastian Engel