我的数据库中有一些值,我想在ListView中显示它们。 这是我的java代码:
public class mallList extends Activity {
protected SQLiteDatabase db;
protected Cursor cursor;
protected ListAdapter adapter;
protected ListView listOfMalls;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.malllist);
db = (new DatabaseHelper(this)).getWritableDatabase();
listOfMalls = (ListView) findViewById (R.id.list);
}
public void searchMall(View view) {
cursor = db.rawQuery("SELECT mall FROM restaurants", null);
adapter = new SimpleCursorAdapter(this, R.layout.mall_list_item, cursor, new String[] {"mall"}, new int[] {R.id.mallview});
listOfMalls.setAdapter(adapter);
}
}
,这是malllist.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/searchButton"
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="searchMall"/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
我想要发生的是在单击搜索按钮时调用searchMall,但每当我点击搜索按钮时,它会显示应用程序(myappname)意外停止。请再试一次。有人可以帮忙吗?