-1

I want to create a Custom listview like this the below image. I am creating a chat app, in that app have to pass text, images and video etc. see below image.

enter image description here

In that, when a user send/receive image in chat, if he wants to see that by clicking on the button beside that image, how to move to another activity with that image path (or) url, for showing full image, and when user clickngi on image have to show a Quick view. same way if that is video, i have to get that path (or) url to play video properly. How to differenciate the list item depends on the item type.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166

2 Answers2

1

You can

  • implement ScrollView and add views into it.
  • create adapter that contains all of the possible views and then decide which view to hide or to show
  • you can create adapter and dynamically add view into each row (in this case it's too slow).

My choise is #2 - create row view with all possible views and then decide what to hide, in this case you can save time because you won't have to inflate you views each time and you can use even ViewHolder pattern.

dilix
  • 3,761
  • 3
  • 31
  • 55
1

If you want to show different rows for audio, image and text messages, you need to have 3 row layouts, then you will decide which row needs to be returned from your getView() of your CustomAdapter. There are two methods getViewTypeCount() and getItemViewType() of Adapter which will help your recycling the row to show up in ListView.

You will first tell that how many layouts in your ListView will be using getViewTypeCount() which tells the adapter how many row types will be there, next check what kind of data is present at that position in your data model and you return the view type from getItemViewType(), so getView() will receive the relevant recycled view (if there is any).

Here is my blog post about using 9 patch images, it demonstrate sender and receiver type of views, same can be applied for image and audio based on the item in your data model at that specific position.

Community
  • 1
  • 1
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153