in my Android App I show the user some messages. Therfore I have Linearlayouts which contain a textview. Whenever the App receives a new message I add a LinearLayout to my page, set the LinearLayout's background to a custom one and then add the TextView to it in code. What I want to do is to create a custom View, which is basically the LinearLayout with a custom background and the textview in it. And/or a View which displays all the messages by itself.
What I want to achieve is that I only have to add one view to my XML-Layoutfile. In my code I then simply add all the messages to a property of the view and those messages are displayed automatically.
I hope you understand what I want to achieve.
Thank you for your help!
It sound like Andre Classen said a RecyclerView is maybe the best way for your. You can create custom layouts for different Cards, Rows, and display them.
Here you find more about the Recycler View with Official Tutorial.
Related
I have to implement a chat in android which should look like in the following image:
How to implement such a ui using listview and adapter?
The row_layout should contain only one message or all messages of one user including his avatar?
Think it should contain only one message, but where to inflate the profile picture for each user at the top of his messages?
Pease help with any suggestions.
Thanks in advance!
you need two layout for this,both consists from an ImageView and a ListView. The only difference between them will be the Gravity( one is Left the Other is Right). And in your out most ListView's getView method, return this two layout based on the data you have.
I am a newbie to android.
I am trying to develop this UI. This is a single row of listview.
I have tried diff ways but not able to this.
Here in this pic, I know how to set that bubble background and use ninepatch and customise listview.
What challenge for me is I want to display some text here after button.
In case if the string is long i.e going to nextline than It should continue below the button.
Please suggest me how to move forward.
Should I use two textviews and check if the first textview is filled than further string should be displayed in the second textview or any other way.
You can use ArrayAdapter or BaseAdapter. Check out the following links
most recommended
link
tutorial1
tutorial
tuorial3
EDIT:
Use seperate Linear Layout for both the view. It should do the trick
I want to create a custom view with some text and two buttons all on one line. I need to be able to add multiple (any number) of these views to an existing layout dynamically (needs to be able to scroll). I want to pass a custom object to the view and set the text and buttons. I need access to the button event handlers from the activity. I've looked a little into custom views but I'm still at a loss for how to do what I want. I'm used to .NET custom controls, and I'm looking for the same effect. Any help or example code would be greatly appreciated.
What you want is custom compound view. You should write you own class (usually extending one of the layouts) and whole behavior, inflate the layout the way you want etc.
More of it: http://developer.android.com/guide/topics/ui/custom-components.html
This one helped me a lot too: http://javatechig.com/android/creating-custom-and-compound-views-in-android-tutorial
If you use list activity or list fragment, you will automatically have the many features you have asked for. You only need to create a adapter class for your listview. You can define your layout for your row view(buttons, text etc..) Try to look at the examples on the web for cusom adapter and lists.
I want to make a customs layout.
In that it contain one Text View and one share button at the bottom
like this
I want to repeat this view for a multiple time like this
it should dynamically add view when new entrees is added to the db.
So can any one help me to solve this problem
Thank's in advance.
Use a grid view. That will help solve your requirement.
I am developing one chat application and i want to create a chat screen layout like following screen.
Currently I am using ListView for my chat texts but the problem is that to read the long chats I have to scroll down,my screen does not scrolls automatically.
I want this bubble kind of chat layout. How do I develop this kind of chat layout?
What you need here is a layout with a header and footer part, having as a main view a ListView.
This ListView should have a custom Adapter to show the message items.
To achieve this bubble-like display, your itemRenderer should be able to deal with states (fromMe - fromOther).
To have the bubbles, you should attach different backgroundDrawable (bubble 9patches pointing to the left and right) to different states.
If you have stuck somewhere, share the relevant code snippets and logcat output, so we can help you further.
try looking at this for creating a custom view for listView.
I would create a parent View and an incoming one and outgoing one that inherit from it and change color and gravity according to the one they are.
You need the following:
A ListActivity, ListView XML Layout.
BaseAdapter which ListActivity Uses.
BaseAdapter getView will inflate each Row.
In Each Row have a row View with you bubble images and your chat text.
In Listview Footer have a EditText View to Type Chat.
Use these for reference:
http://developer.android.com/reference/android/app/ListActivity.html
http://developer.android.com/reference/android/widget/BaseAdapter.html
OK if I understand you correctly all you need to do is implement auto-scroll for the Listview.
if so then try calling smoothScrollToPosition each time something is added. I don't know what your class looks like but maybe can run something like this (pseudo code)
customListview.addNewChat(...);
customListView.smoothScrollToPosition(customListView.getCount());