android custom listview row formatting question - android

I have a listview that I am trying to customize. The issue I am having with eclipse's android plugin is I am not quite sure how to format the text portions and wrap them around my icon. Here is a diagram with what I am trying to do:
I need to know,
1. Advice on formatting text to fit the row. for the top, i want 3 different strings to fit (what they can) into their own column and ellipsise at the end. easy enough.
2. I want to do something similar for the bottom row but give it a max length. Say each column can contain up to 20 characters, including the (...) ellipses. it may contain 1-7 columns. So I want the overflow to go to the next row and wrap under the icon.
3. Perhaps someone has a war story with a custom listview they want to share? How did you fit all the information in the item, or did you use an alternate view such as GridView instead?
Thank you.

For point 1: You can use LinearLayouts for each row, using the weight property on each element according to your needs.
For point 3: in order to make the text to ellipsise you can use the property
android:singleLine="true"
although it has deprecated, or use
android:inputType
with anything in order to not set the textMultiLine flag into true
For point 2: i cant think of doing this in other way than programatically

Related

Give a possible way to display data

tell me how best to implement the following representation of information
20.10.2014
7:00 some text
7:30 some text
18:00 some text
21.10.2014
7:20 some text
7:21 some text
7:22 some text
22.10.2014
7:20 some text
I know the following solution - ExpandableListView but then the children can curl up. but I do not need or TableLayout with TableRow but I need to fill in the data from the array and implement the click event for each element except the parent.if you ask a stupid question and give direction where to look, I'll delete it
even without the events. usual display of text from a file in a form
Option 1: Use Multiple Views in ListView
See this tutorial and this answer (it is harder one you will need a simple adapter).
It will help you in creating a adapter with two different layouts.
Option 2: if you don't want it to be so much complicated use simple base adapter and create a view with both date layout and event layout and change it's visibility.
Option 3: In More Simple way create a mutliline text view in scrollView then make your text more formatted using spannable string.

Contact list design suggestion

I'm constructing a custom contact list with 5 required fields. It's a bit difficult to fit all 5 in a single row without looking like it's cluttering or doing nested rows which make it hard to distinguish the rows. Here are a couple of designs that I came up with (below). Is there a better way to organize the fields, such as expanding the row when selected to reveal more info, or simply make the row height bigger? Any suggestions?
Not so clear what your five fields are. Most important field(s) (e.g. name or contact number) should be at the top in bold style. The second row should contain less important fields, but you need to put enough spaces and style to distinguish them. You should also use ellipsize(...) attribute to contain them within the boundary. If it is important to show the whole string, you may even use third row for any field. Hope this helps.

Multiple images in one TextView?

I would like to know what is the best way to place multiple, small(all of them the same size) images into one TextView? From what I've found, the best way would be to use Html, but how? All of my images are offline ones, so I can copy them for example in the raw folder, if that is the right way. Can anyone point me into the right direction, or show a similar thread, which I did not find? OR, is there any better approach, like don't use TextView, but something else, which can be solved in the layout files, and dynamically filled with images?
Btw, the whole thing I want to do is:
I have a ListView, filled with items
each item has different attributes, which I currently print in plaintext(I want to replace theese with images
atm, I use one separate TextView to display theese attributes
the number of attributes are random, but at least 1, and typically 3-4(so 1 picture at least, 3-4 typically)
cheers
Sounds like you are making smileys in a chat/message application, am I right? ;)
Anyway, the way to go is to use an ImageSpan. You can use a Matcher to find all text combinations you want to replace, and use a SpannableStringBuilder to add ImageSpans to the positions returned by the matcher, this will replace those characters with the image defined by the ImageSpan.
Why not just create a layout that can be used for each row of your ListView and populate the different elements of that layout based on the data for the row?
For example, if each item has a maximum of 4 attributes, add four ImageViews to the layout, and set their drawables and visibility in getView based on the position passed in.
One thing is for sure : You do not want to put your images inside your textview.
A textview can contain a background but should not be used to contain images.
What you want to do is simply design an item layout that will be used by your adapter to fill the listview.
This item layout will contain a textView that contains only your text and your images. Then in your listAdapter you'll simply show or hide the images you want.
Try to base your layout on a RelativeLayout that will allow you to have a simpler design and even overlap some elements(the images could overlap the textview for example)

Android DB List Adapters: multiple columns, aligned?

Ok I can't find a sample anywhere.
I've done the notepad tutorial on Google's Android site, but I would like to know how to add more fields to the list, in columns. At the moment I can add the columns no problem, but they're not aligned like you would a normal table on the layout:
john smith
heinrich cilliers
will peck
I would like the first names and last names aligned proportionately, as you would in an html table.
It works if I use a constant value for the layout_width parameter (100dip etc), but I would prefer to use a relative percentage. However it's becoming clear that each row is on it's own, and does not know how to alighn itself with the row above.
Any pointers?
UPDATE: I've reached an experienced Android developer which advised me to use WeightSum, which brings me closer, but vertical alignment is stil not happening:
I think therefor you have to extend the ListAdapter.
http://developer.android.com/reference/android/app/ListActivity.html

android repeater-like functionality

is there any type of 'repeater' type functionality in android? I have a relative layout (inside a row in a listview) and inside that I'd like to have a series of TextViews be displayed one after the other (as if they are child rows in the listview row). The issue is that the number of those "child rows" will vary. is there any way to do this, or should i just create the TextView objects in code, and programatically add them to a linear or table layout?
The closest thing (besides ListView/ListAdapter, naturally) that I can think of offhand is ViewSwitcher and ViewSwitcher.ViewFactory, but there's really nothing magical there: it's an interface that you can call to get a view.
Since it's only one line to get a view and add it to your current hierarchy anyways, though (View.inflate(context, R.layout.somelayout, myContainerViewGroup)) it feels silly to go with something heavier, but if you feel better wrapping that up in a Factory of some sort, check the AOSP source for ViewSwitcher.
One option is TextViews support Multi-line text. So you could create the text with a StringBuilder using "\n" for new lines, and not have to worry about multiple text views.

Categories

Resources