I have a sqlite db I’m using to store my info and I have four column headings weighted out to ‘1’. I have a problem reading the data as it bunches it all up in the middle and covers up one of my column headings. What am I doing wrong or is there another way I should be displaying the information? Thanks
Here is the code:
here is the view xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Date" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Time" />
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Hair Wash" />
<TextView
android:id="@+id/textView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Comments" />
</TableRow>
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="get info from db" />
</TableLayout>
</LinearLayout>
here is the view java
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bathreport);
TextView tv = (TextView) findViewById(R.id.textView3);
MyDBAdapter info = new MyDBAdapter(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
}
My adapter’s getdata
public String getData() {
String[] columns = new String[] { /*KEY_ROWID,*/ KEY_BATHDATE,
KEY_BATHTIME, KEY_HAIRWASH, KEY_COMMENTS };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
null, null);
String result = "\n";
//int iRow = c.getColumnIndex(KEY_ROWID);
int iDate = c.getColumnIndex(KEY_BATHDATE);
int iTime = c.getColumnIndex(KEY_BATHTIME);
int iHair = c.getColumnIndex(KEY_HAIRWASH);
int iCom = c.getColumnIndex(KEY_COMMENTS);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result + /*c.getString(iRow) + " " +*/ c.getString(iDate)
+ " " + c.getString(iTime) + " " + c.getString(iHair) + " "
+ c.getString(iCom) + "\n";
}
return result;
}
I guess a better implementation is to use a SimpleCursorAdapter:
The layout above should contain 4 TextViews in one Horizontal Linear layout (similar to your Table row implementation), the from is your column names and the to is the Ids of the 4 TextViews
Then set this adapter as the adapter of a ListView that should replace your Table