我怎样才能准确地获取TableLayout中的数据

时间:2013-11-24 16:23:59

标签: java android sqlite c#-4.0 facebook-graph-api

我正在尝试显示来自数据库的数据,就像我设置表格coloumn但我失败加载我怎么能这样做,请帮助我。

我的

数据库方法
//return all data in tabular form Project_Database.java activity

public String Foodgetdata() {
// TODO Auto-generated method stub
String[] columns = new String[] {Food_RowID, Food_Date, Food_Price, Food_Cashtype,        
Food_Comnts };
Cursor c = ourdatabase.query(Food_TABLE, columns, null, null, null, null, null);
String result = " ";
int FRow = c.getColumnIndex(Food_RowID);
int FDate = c.getColumnIndex(Food_Date);
int FPrice = c.getColumnIndex(Food_Price);
int FCashtype = c.getColumnIndex(Food_Cashtype);
int Fcomments = c.getColumnIndex(Food_Comnts);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(FRow) + " " + c.getString(FDate) + " " + 
c.getString(FPrice) +  " " + c.getString(FCashtype) + " " + c.getString(Fcomments) +   
"\n";

}
return result;
}

在这个类名Food_.java中我想要检索数据

public class Food_ extends Activity {

TextView tv ;
//TableLayout foodlayout;
//final TableRow trhead = new TableRow(this);
//TextView txtid = new TextView(this);
//TextView txtdate = new TextView(this);
//TextView txtprice = new TextView(this);
//TextView txtcashtype = new TextView(this);
//TextView txtcommnts = new TextView(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_all_food);

    tv = (TextView) findViewById(R.id.tvsql);
    Project_DataBase info = new Project_DataBase(this);
    info.open();
    String data = info.Foodgetdata();
    info.close();
    tv.setText(data);
}
}

这是我的view_all_food xmlfile

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/foodtablelayout"
android:orientation="vertical" >


<TableLayout
    android:id="@+id/foodtablelayout"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:layout_weight="1.54"
    android:stretchColumns="0,1,2,3,4" >

    <TableRow
        android:id="@+id/foodrows"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FF45FF" >

        <TextView
            android:id="@+id/foodIDcol"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="ID" />

        <TextView
            android:id="@+id/foodDATEcol"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="Date" />

        <TextView
            android:id="@+id/foodPRICEcol"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="Price" />

        <TextView
            android:id="@+id/foodCASHcol"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="CashType" />

        <TextView
            android:id="@+id/foodCOMMcol"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="Comments" />          
    </TableRow>

</TableLayout> 
<TextView
    android:id="@+id/tvsql"
    android:layout_width="fill_parent"
    android:layout_height="330dp"
    android:text="Get info from Data base" />

</TableLayout>

0 个答案:

没有答案