How to add header to Multicolumn ListView - android

I couldn't find this question already being asked on this forum.
I am little short on time to search anymore.
I have a multi-column ListView with three TextViews.
I need to have header for each of the column. I am using Android 1.5 SDK.
Can somebody help me here. I can't use addHeaderView since it adds just one view which would contain just one title string.
Thanks
Nayn

One easy solution to this will be to use same layout params for the header as you are using for the list item.Eg:
If you have three TextViews, suppose 1st one is right aligned, 2nd one is to the left of this and 3rd one is to the left of second one. Now for the header as you have separate headers for each column, you can use the same layout params for the three column headers i.e 1st one is right aligned, 2nd one is to the left of this and 3rd one is to the left of second one.
This is just an eg. the basic idea is to keep layout params(relative position,margins,padding,etc) same for both of them.
I tried this and it works for me.

I added a separate table above the list view which has all the columns listed. This solves my problem. Just that data is not aligned properly with the columns. I'll think about it later

Related

Dynamically set the number of textview in a given space

In my app I want to show tags to the users. As of now am showing only 5 tags.
P.S. Ignore the color part.
As of now am using 5 different TextView with wrap content to show the text.
But as you can see, in the latter case, there are lot's of empty space in the top row.
Is there any way by which I can dynamically select the number of tags to be fetched from server which will fit in the given space?
Like in the 2nd case, I can show 3 tags in the first row and 3 in the second row. I'll like to fix a Tab space between two tags and based on available spcae, the number of tags should be displayed.
Given the layout you posted you could use a TableLayout setting android:stretchColumns="*", this will stretch all columns and make it "tabular"
Try using FlowLayout. It works the same way as you want.

how to make listview like android market . i.e divided into two columns

I was wondering how to implement the listview like the android market.
in the right hand panel a listview is divided into the two rows. This is very useful because it saves lot of space and user can look at almost double items in the listview at a time. how can I implement this ? any suggestions?
you can use GridView instead of ListView of two columns..
1. GridView
2. GridViewExample
Sample design :
The Android Market also uses the ViewPager to scroll between the pages. Here is an example on how you could implement it.
There is another question that is related to this one.Check the folling link, it might help you:
How to display a two column ListView in Android?
Modify you *.xml file to get what you want.
Good luck!
If you want to do this using listView, then each item (row) in the list view should consist of two views. You can do this using a relative layout (or linear layout) with two items side by side.
You can also implement this using a gridview having two columns.

Dynamically add column elements to a Android ListView

After reading Dynamically add elements to a listView Android , I understand clearly how to dynamically add row elements to a listView.
However, I have one idea that how to dynamically add column elements to a listview.
For example, there are 2 columns originally. After I click a button, I would like to add one one more column.
Can anyone provide example code?
Thank for all sharing.
Just add rows dynamically, but make a custom view with two different elements... So there'll be two elements on your every view of row. And first, set first items while seconds are invisible and after clicking button set others... So it'll seem that you're adding column...

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

Image in a custom List Android

I have created a custom adapter to display a list, there is an image that is displayed in each row ( the image is the same for all rows, except using an array i am assigning it different values depending on the position). An xml file defines the relative layout that i am using. My problem is that i can either get the entire row to be clickable or nothing at all, I only want this image to be clickable, instead of the entire row. How would i be able to do this ? i am new to android and am pretty much following different tutorials trying to create my list. Any help would be appreciated.
layout is like this :
TEXT:
[Image]
TEXT:
thats wat a row looks like...getting two texts from two different arrays and shows it, a third array is used to link to the image. I just want this image to be clickable instead of the entire row.
Thanks
Android's list component manages clicks per row. This makes it very difficult to achieve what you want to do. Two solutions come into mind:
1) If your list is never very long you could simply use linear layout and scroll view to build the list. This approach won't work if you fill in the list dynamically and you can't be sure that there won't be a very large number of rows as it would use too much memory in that case.
2) Other option is to use ListView but make your text components and images different view types in list ie. break you row into three.
That can be achieved overriding list adapter's getItemViewType(int)
http://developer.android.com/reference/android/widget/Adapter.html#getItemViewType(int)
In this approach you can make the image rows clickable but the text rows not.

Categories

Resources