我试图从sqlite数据库中获取数据并将其放在表中,但它的工作原理但问题是来自数据库的数据是这样的:
http://oi59.tinypic.com/30bpiz9.jpg
我想要订购数据,并且要像这样排成行:
我的xml文件
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Id"
android:layout_weight="1" >
</TextView>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:layout_weight="1" >
</TextView>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:layout_weight="1" >
</TextView>
</TextView>
</TableLayout>
<TableRow android:id="@+id/tableRow2" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:id="@+id/tvSQLinfo"
android:layout_width="fill_parent"
android:layout_height="34dp"
android:background="@drawable/cell_shape"
android:text="get the info from database"
/>
</TableRow>
我的java文件
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[] { KEY_ID, KEY_NAME, KEY_EMAIL};
Cursor c = ourDbase.query(TABLE_USER, columns, null, null, null, null, null);
String result ="";
int aRow = c.getColumnIndex(KEY_ID);
int aName = c.getColumnIndex(KEY_NAME);
int aEmail = c.getColumnIndex(KEY_EMAIL);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(aRow) + c.getString(aName) + c.getString(aEmail) + "\n";
}
return result;
}