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

1

2 Answers 2

2

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

Have a look here.

Sign up to request clarification or add additional context in comments.

2 Comments

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
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 :)
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

4 Comments

Not that good, it's only changing the background, i have several views which need layout direction change also.
You can build your list item that you just need to adjust the gravity/text/image for recycled view
That's not possible, i need to change the direction of all view, not just left/right gravity and bg image...
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.