在android中显示具有sqllite数据库值的表?
我想在ui中显示表,数据来自sqllite数据库表。我如何在安卓系统中实现?通过以下步骤,我创建了包含静态内容的表:在android中显示具有sqllite数据库值的表?,android,database,sqlite,Android,Database,Sqlite,我想在ui中显示表,数据来自sqllite数据库表。我如何在安卓系统中实现?通过以下步骤,我创建了包含静态内容的表: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tableLayout1" android:layout_width
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="@+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="18dp"
android:text="Weather Table"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:id="@+id/TextView04"
android:text=""></TextView>
<TextView
android:id="@+id/TextView04"
android:text="Feb 7"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="@+id/TextView03"
android:text="Feb 8"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="@+id/TextView02"
android:text="Feb 9"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="@+id/TextView01"
android:text="Feb 10"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:text="Feb 11"
android:id="@+id/textView1"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:id="@+id/tableRow2"
android:layout_width="match_parent">
<TextView
android:text="Day High"
android:id="@+id/textView2"
android:textStyle="bold"></TextView>
<TextView
android:id="@+id/textView3"
android:text="28°F"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="26°F"
android:id="@+id/textView4"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="23°F"
android:id="@+id/textView5"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="17°F"
android:id="@+id/textView6"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="19°F"
android:id="@+id/textView7"
android:gravity="center_horizontal"></TextView>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:id="@+id/tableRow2"
android:layout_width="match_parent">
<TextView
android:text="Day Low"
android:id="@+id/textView2"
android:textStyle="bold"></TextView>
<TextView
android:text="15°F"
android:id="@+id/textView3"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="14°F"
android:id="@+id/textView4"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="3°F"
android:id="@+id/textView5"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="5°F"
android:id="@+id/textView6"
android:gravity="center_horizontal"></TextView>
<TextView
android:text="6°F"
android:id="@+id/textView7"
android:gravity="center_horizontal"></TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<TextView
android:id="@+id/textView8"
android:text="Conditions"
android:textStyle="bold"></TextView>
<ImageView
android:id="@+id/imageView1"
android:src="@drawable/hot"></ImageView>
<ImageView
android:id="@+id/imageView2"
android:src="@drawable/pt_cloud"></ImageView>
<ImageView
android:id="@+id/imageView3"
android:src="@drawable/snow"></ImageView>
<ImageView
android:id="@+id/imageView4"
android:src="@drawable/lt_snow"></ImageView>
<ImageView
android:id="@+id/imageView5"
android:src="@drawable/pt_sun"></ImageView>
</TableRow>
</TableLayout>
请看一次如何在Android中向该行添加动态值,并在Android前端应用程序中显示表 您必须在xml中创建一个类似下面的表
<TableLayout
android:id="@+id/rows_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:padding="10dp"
android:background="color or drawable"
android:shrinkColumns="*"
android:stretchColumns="*"/>
您可以在AsyncTask PostExecute
中或您希望的地方执行以下操作
// entries are the no.of that you decided to print dynamically.
int rows;
for (rows=0;rows<entries.length();rows++)
{
TableRow trTwo = new TableRow(Activity.this);
trTwo.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.FILL_PARENT));
// Here you can get the cursor data , which is going to be displayed in the coloumns.
//entriesVar is the coloumn data.
for(int coloumn = 2; coloumn < entriesVar.length; coloumn++)
{
//Your database values
if (coloumn == 1)
{
//Any Header options, If you wish to show any table headers
}
String questionable = "sometext";
TextView txtTwo = new TextView(ReportsActivity.this);
txtTwo.setText(questionable);
txtTwo.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
txtTwo.setTextColor(Color.BLACK);
txtTwo.setGravity(Gravity.CENTER);
txtTwo.setBackgroundResource(R.drawable.table_border_new);
txtTwo.setPadding(3, 3, 3, 3);
trTwo.addView(txtTwo);// Binding Text To Row
}
// Adding View To Table
RowsTable.addView(trTwo, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
//条目是您决定动态打印的编号。
int行;
for(rows=0;rowsi拥有cusor中的所有数据,或者如何通过任何循环为其追加数据以进行重复?dbadapter.open();Cursor Cursor=dbadapter.fetchordersdata(custid);int count=Cursor.getCount();String ordernum=Cursor.getString(0);String pId=Cursor.getString(1);String Pqty=Cursor.getString(2);System.out.println(“*********计数::::”+COUNT);System.out.println(“*********行:::”+ordernum);System.out.println(“******************PID:::”+PID);System.out.println(*********PQTY::”+PQTY);这些是我的db值如何在上面的代码中设置?感谢您的回复,您需要在每行中显示ordernum、pid、pqty。对吗?因此,请在此处循环光标(int-coloumn=2;coloumn// entries are the no.of that you decided to print dynamically.
int rows;
for (rows=0;rows<entries.length();rows++)
{
TableRow trTwo = new TableRow(Activity.this);
trTwo.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.FILL_PARENT));
// Here you can get the cursor data , which is going to be displayed in the coloumns.
//entriesVar is the coloumn data.
for(int coloumn = 2; coloumn < entriesVar.length; coloumn++)
{
//Your database values
if (coloumn == 1)
{
//Any Header options, If you wish to show any table headers
}
String questionable = "sometext";
TextView txtTwo = new TextView(ReportsActivity.this);
txtTwo.setText(questionable);
txtTwo.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
txtTwo.setTextColor(Color.BLACK);
txtTwo.setGravity(Gravity.CENTER);
txtTwo.setBackgroundResource(R.drawable.table_border_new);
txtTwo.setPadding(3, 3, 3, 3);
trTwo.addView(txtTwo);// Binding Text To Row
}
// Adding View To Table
RowsTable.addView(trTwo, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}