【发布时间】:2015-10-09 06:39:32
【问题描述】:
我通过以下方式在数据库中填充我的数组列表:
db.addBookMark(new BookMark("Ravi", "9100000000"));
db.addBookMark(new BookMark("Srinivas", "9199999999"));
db.addBookMark(new BookMark("Tommy", "9522222222"));
db.addBookMark(new BookMark("Karthik", "9533333333"));
并通过以下方式读取(数据库中的所有项目):
// Reading all contacts
List<BookMark> bookmarks = db.getAllBookMarks();
我创建了一个 xml 布局 listview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.wepars.webapp.activity.MsgActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
还有行项目row_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
我之前读过this question..但它适用于一个简单的列表。如何在 listview 中发布我的 2 钻石列表?
我尝试完成这段代码:
public class BookMarkActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
DatabaseBookMark db = new DatabaseBookMark(this);
Log.d("Insert: ", "Inserting ..");
db.addBookMark(new BookMark("Ravi", "9100000000"));
db.addBookMark(new BookMark("Srinivas", "9199999999"));
db.addBookMark(new BookMark("Tommy", "9522222222"));
db.addBookMark(new BookMark("Karthik", "9533333333"));
// Reading all contacts
List<BookMark> bookmarks = db.getAllBookMarks();
}
}
【问题讨论】:
-
您的代码中的 2 钻石列表 在哪里???粘贴正确的代码。
-
@Clairvoyant 例如,对于我想在 Textview(id=message)中显示“Ravi”和在另一个 Textview(id=number)中显示“9100000000”的每一行......我编辑了我的代码跨度>
-
您是否创建了
adapter并将array或arraylist传递给它??
标签: android listview android-listview