0

さまざまな文字列の長さの 5 つの列を持つデータベースからテーブルを表示したい.これを表示する最良の方法です。

私のlayout.xmlコード:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">           

     <TextView android:id="@+id/text1"      
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" /> 

     <TextView android:id="@+id/text3"          
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_alignParentRight="true"/>

     <TextView android:id="@+id/text5"          
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_alignParentRight="true"/>

     <TextView android:id="@+id/text7"          
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_alignParentRight="true"/>

     <TextView android:id="@+id/text9"          
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_alignParentRight="true"/>

     <TextView
        android:id="@+id/textView21"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/> 

</LinearLayout>

ジャバコード:

super.onCreate(savedInstanceState);
setContentView(R.layout.report);            
String[] from;
int[] to;
db.open();          
ListView lv=(ListView)findViewById(R.id.listView1);     
Cursor c = db.getEducationTitle();

while(c. moveToNext())
{
    // Cursor c = db.getEducationTitle();
    LinearLayout linearlayout=(LinearLayout)findViewById(R.id.Layout1);
    TextView edt=(TextView) new TextView(getApplicationContext());
    edt.setText(c.getString(c.getColumnIndex("col1"))+" "+c.getString(c.getColumnIndex("col2"))+" "+c.getString(c.getColumnIndex("col3"))+c.getString(c.getColumnIndex("col4"))+" "+c.getString(c.getColumnIndex("col5")));
    linearlayout.addView(edt);

}
4

1 に答える 1

0

これを試して....

 SQLiteDatabase db=openOrCreateDatabase("databasename", MODE_PRIVATE, null);
    Cursor c=db.rawQuery("SELECT * FROM tablename, null);
    c.moveToFirst();
    LinearLayout linearlayout=(LinearLayout)findViewById(R.id.linearlayout);

       while(cursor.moveToNext)
        {

                TextView edt=(TextView) new TextView(getApplicationContext());
                edt.setText(c.getString(c.getColumnIndex("col1"))+" "+c.getString(c.getColumnIndex("col2"))+" "+c.getString(c.getColumnIndex("col3"))+" "+c.getString(c.getColumnIndex("col4"))+" "+c.getString(c.getColumnIndex("col5")));
                linearlayout.addView(edt);

        }
于 2012-07-12T05:33:29.963 に答える