Question

how to creat a Arraylist adapter which will change the view based on a flag in the LISTVIEW, Flag can be IMAGE , IMAGETEXT, VIDEO , VIDEOTEXT, TEXT

e.g like in facebook post , 1. if a friend posts a text, list row will only contain a text with his Name 2. if a friend posts a Image , list row will only contain a image with his Name 3. if a friend poasts a Video , list row will only contain a Video with his Name , and only Video onClick() , Playing that Video in a external Player

  1. Flag = text. view to be attached is text.xml
  2. Flag = Video, View to be attached is video.xml
  3. Flag = Image ,View to be attached is image.xml

ANY HELP ON THIS.

Thanks in Advance...

Was it helpful?

Solution 3

i implemented similar Custom Adapter for ListView which is used in this link , also used ViewHolders

check this link

http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/

OTHER TIPS

override getItemViewType(int position) and getViewTypeCount() method in your adapter and inflate you view according to it from getView(). In you case write methods like

 @Override
public int getItemViewType(int position) {
        if(list.get(position).flag == text)
            return 0;
         else if(list.get(position).flag == image) 
            return 1;
         else
            return 2;         
}

@Override
public int getViewTypeCount() {
    return 3;
}    

I am not pretty much sure but it's my concept that firstly create a layout for row that can hold every thing that you want show(image, video, text etc ). And make this layout such a way if one thing is not present then it automatically wrapped(means if video is not present then video space will not be there). Now make json of every list row and pass it to Adapter of list. Then override getView() method of the
adapter and parse json there and display according to your layout.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top