well basicly I'm getting data from a database and I want to adapt this data in a kind of "DataGridView" on any other lenguaje, Basicly I have an GridView in a Main layout define like this:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gastoGridView"
android:stretchMode="columnWidth"
android:cacheColorHint="#00000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="1"
android:clipChildren="true"
android:horizontalSpacing="5dip"
android:verticalSpacing="5dip" />
other hand I have a second xml layout file than define every item(row) for this gridView, It is my item_gridview xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout android:id="@+id/TableLayout01"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TableRow android:id="@+id/TableRow01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView android:text="@string/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fechaAtt"
android:gravity="left"
android:layout_gravity="left" />
<TextView android:text="@string/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/descpAtt"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal" />
<TextView android:text="@string/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/saldoAtt"
android:layout_gravity="right" />
</TableRow>
</TableLayout>
Ok, basicly I'm getting 3 attributes from database, I already developed the adapter to this gridview, so I show the information on it, but not in the way I want, I'll try to explain you, Currently it's being show like this
| Date | Description | Price |
2014-11-17 any description it have 50.85$
I'm trying to divide my tablerow (width:fill_parent) on 3 sections(columns) I'm not sure if It's possible, because I'm not very involved on this subject, but I want to divide this tablerow on those 3 section, I want a small section on the left side of the row which will be my date, a large section in the center_horizontal wich will be my Description, and another left section wich will be my price, I'm not sure if you guys get my point but I want some like this.
| Date | Description | Price |
2014-11-17 Get the description Centered Here 50.85$
I've tried to use the layout_span and layout_column on every TextView, but I get a Null Pointer error which I don't understand, maybe I'm doing that in a wrong way.
Could you guys help me to get this style? I've been reading about it a lot, It's a kind of difficult because Android do not support an DataGridView tool as others lenguages do.
Thanks you beforehand, I really need it
Your difficulty stems from the fact that your trying to bring your concept of the DataGridView into Android which is problematic. What you really want to do use a
ListViewwith a properAdapterandLoader(use aLoaderif possible).Now, with a
ListViewwhat happens is it createsViewfor every row returned from theCursorusing theAdapterto create (inflate) this view and populate it (binding). This is useful since you can now think about each row as a set of three items and lay them out appropriately. I recommend just using the regularLinearLayoutwith the appropriatelayout_weightset for your layout. You'll have to remember to set theLinearLayoutto horizontal.Edit:
For clarification. With
LinearLayoutyou can specify in the layout.xml file theandroid:layout_weightparameter. This allows you to set 'relative' sizes (width or height depending on horizontal or verticalLinearLayout). Once you do this theandroid:layout_widthis ignored but you should set it to 0dp. An Example:Now you have three
TextViewin a horizontalLinearLayouteach with a weight set to1. That would make them all equal size. You can adjust the weight values to change their relative sizes to each other and the parent width.