2

I'm building an sms app, and need to show the view according to Incoming/Outgoing sms. I'm facing the following issue, in my getView(..) I need to know if it's Incoming/Outgoing and then to show the following:

Incoming VIEW

Incoming VIEW

Outgoing VIEW

enter image description here

But i can't think of a way to implement 1 view to handle this (because of the recycling in listview).

I thought of using setLayoutDirection in a LinearLayout, or maybe removeViews and then add them in correct position. Can you please assist me with the best way with the less performance?

Thanks very much

Udi Oshi
  • 6,787
  • 7
  • 47
  • 65
  • 1
    http://stackoverflow.com/questions/18868194/android-xml-layout-for-a-listview-with-different-items. check this – Raghunandan Feb 25 '14 at 14:36

2 Answers2

2

You can override the getViewType method in order to precise how many kind of rows you listview has.

Have a look here.

Community
  • 1
  • 1
S.Thiongane
  • 6,883
  • 3
  • 37
  • 52
  • Yeah i've been thinking of this, but isn't this option has high performance? also, second time the view already inflated with RTL and its not null and I need to change it to LTR, this isn't help me much – Udi Oshi Feb 25 '14 at 14:47
  • Sorry, but i don't know if it has high performance ! I don't think also that there is another solution to have different rows in a list, without overriding this method ! Just respect the recycling pattern and let android do the rest for you :) – S.Thiongane Feb 25 '14 at 15:03
0

Here is a simple example how to achieve it with good performance: http://adilsoomro.blogspot.fi/2012/12/android-listview-with-speech-bubble.html

Niko
  • 8,093
  • 5
  • 49
  • 85
  • Not that good, it's only changing the background, i have several views which need layout direction change also. – Udi Oshi Feb 25 '14 at 14:45
  • You can build your list item that you just need to adjust the gravity/text/image for recycled view – Niko Feb 25 '14 at 14:50
  • That's not possible, i need to change the direction of all view, not just left/right gravity and bg image... – Udi Oshi Feb 25 '14 at 15:01
  • I don't understand how it's not possible, RelativeLayout as ViewGroup and alignParentLeft/alignParentRight with toLeftOf and toRightOf? Can you post better image of your cases? – Niko Feb 25 '14 at 17:16