我已经完成了从表中派生数据的编码,并在 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,并通过单击下一步移动到下十行。
请提供建议以实现这一目标。
提前致谢。
问候, 迪内什