我一直在努力解決這個問題,但似乎無法找到我在尋找的搜索谷歌過去幾天,我打了,錯過了東西,是傾向於我想做的事情,但沒有碰到任何我想做的事情。我開始建立我的SQLite數據庫以及「TheNewBoston Android Tuts」一切正常,現在我試圖改變視圖數據庫周圍的錯誤,或者在啓動時崩潰應用程序。我想要使用for循環來顯示數據庫中某行中的某些列,並使用for循環來動態加載TableView:Android SQLite:顯示數據條目
DbEntry [data |數據|顯示|數據|顯示|顯示|數據]
我可以做到這一點,如果我有一個自己的TextView關閉,但與它在TableLayout> TableRow我認爲這是問題的地方,但不知道...希望能夠加載錶行如果可能的話,從類自身而不是設置文本視圖。我希望我給了我想要做的足夠的信息,如果任何人都可以指向我一個非常好的教程,或者對此有所瞭解,那麼我將非常感激。
XML:
<TableLayout
android:id="@+id/view_Table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/view_DbCol3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DB Col 3 Displayed Data" />
</TableRow>
與XML我希望我通過把錶行於側彼此
SQLview類
setContentView(R.layout.sqlview);
TextView tv = (TextView) findViewById(R.id.view_DbCol3);
try {
DBload info = new DBload(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
} catch (Exception e) {
// Error Message Dialog
String error = e.getLocalizedMessage();
Dialog d = new Dialog(this);
d.setTitle("DB ERROR");
TextView tv1 = new TextView(this);
tv1.setText(error);
d.setContentView(tv1);
d.show();
}
做右表,它類似於HMTL樣的東西
DbHelper類:GetData方法
public String getData() {
String[] cols = new String[] {KEY_PLACE};
// I have also tried with all my KEY variables
// reads info from DB columns
Cursor c = ourDB.query(KEY_TABLE, cols, null, null, null, null, null);
String result = "";
int Ione = c.getColumnIndex(KEY_PLACE);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result
+ c.getString(Ione)
+ "\n";
}
return result;
}
我正的誤差是
11-17 00:13:09.993:E/CursorWindow(590):爲字段時隙0爲請求,-1。 = numRows行2,爲numColumns = 1
就像我說的,我希望我已經給了足夠的信息,幫助不大,如果可能的話,非常感謝
只需使用listview ...在sdk文件夾中找到示例... NotePad項目或ApiDemos中的List7.java – Selvin