0

テーブルからデータを取得し、テーブルの列と行として Android ビューに表示するための次のコーディングを行いました。

データベースのコーディングは

public List<Country> getAllCountry()
{
    List<Country> countryList = new ArrayList<Country>();

    //select query
    String selectQuery = "SELECT * FROM COUNTRY_LIST";

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);


    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
    {
         Country country = new Country();
            country.setId(cursor.getString(0));
            country.setName(cursor.getString(1));
            country.setNationalty(cursor.getString(2));
            country.setDate(cursor.getString(3));


            // Adding person to list
            countryList.add(country);
    }

    return countryList;

}

XML は

<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab">
  <TableRow
      >        
  </TableRow>    
</TableLayout>

アクティビティコーディングは

List<Country> country = db.getAllCountry();

    StringBuilder builder = new StringBuilder();
    for (Country c: country)
    {               
        builder.append(c.getId()).append(";")
            .append(c.getName()).append(";")
            .append(c.getNationalty()).append(";")
            .append(c.getDate()).append("_");
    }
    //tv.setText(builder.toString());

    builder.toString();

    String st = new String(builder);
    Log.d("Main",st);
    String[] rows  = st.split("_");
    TableLayout tableLayout = (TableLayout)findViewById(R.id.tab);
    tableLayout.removeAllViews();

    for(int i=0;i<rows.length;i++){
        Log.d("Rows",rows[i]);
        String row  = rows[i];
        TableRow tableRow = new TableRow(getApplicationContext());
        tableRow.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        final String[] cols = row.split(";");

        Handler handler = null;

        for (int j = 0; j < cols.length; j++) {             
            final String col = cols[j];                                 
            TextView columsView = new TextView(getApplicationContext());
            columsView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
            columsView.setTextColor(color.black);
            columsView.setText(String.format("%7s", col));                                
            Log.d("Cols", String.format("%7s", col));
            tableRow.addView(columsView);                
            }
         tableLayout.addView(tableRow);

    }

データベースから値を表示する上記のプログラムがあります。

今、私は番号を制限したいと思います。表示する行数が 10 行になり、[次へ] をクリックすると次の 10 行に移動します。

これを実現するためのアドバイスをお願いします。

前もって感謝します。

よろしく、 ディネシュ

4

1 に答える 1

1
cursor = database.query(TABLE_NAME, 
                new String[] {NAME_OF_COLUMNS} ,
                null, null, null, null, null ,limit);

必要に応じて制限の値として整数を渡します

于 2013-08-01T11:43:06.000 に答える