构造函数 SimpleCursorAdapter(ShoppingList, int, Cursor, SQLiteDatabase, ListView) 未定义
当我使用 SimpleCursorAdapter 时,Eclipse 说构造函数 SimpleCursorAdapter(ShoppingList, int, Cursor, SQLiteDatabase, ListView) 未定义。
这是我的.java:
package com.shoppinglist;
import java.util.Locale;
import android.app.Dialog;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class ShoppingList extends ListActivity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listview = (ListView) findViewById(android.R.id.list);
SQLiteDatabase db;
db = openOrCreateDatabase("Items.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String CREATE_TABLE_ITEMS =
"CREATE TABLE tbl_items ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "item_name TEXT);";
db.execSQL(CREATE_TABLE_ITEMS);
Cursor c = db.query(CREATE_TABLE_ITEMS, null, null, null, null, null, null);
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.rowlayout, c, db, listview);
setListAdapter(adapter);
Button button1main = (Button) findViewById(R.id.add);
button1main.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog additem = new Dialog(ShoppingList.this);
additem.setContentView(R.layout.maindialog);
final EditText et = (EditText)additem.findViewById(R.id.edittext);
additem.setTitle("Type your item");
additem.setCancelable(true);
et.setHint("Type the name of an item...");
Button button = (Button) additem.findViewById(R.id.cancel);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
additem.dismiss();
}
});
additem.show();
Button ok = (Button) additem.findViewById(R.id.ok);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String text = et.getText().toString();
additem.dismiss();
et.setText("");
}
});
}
});
}
}
When I use a SimpleCursorAdapter, Eclipse says The constructor SimpleCursorAdapter(ShoppingList, int, Cursor, SQLiteDatabase, ListView) is undefined.
Here is my .java:
package com.shoppinglist;
import java.util.Locale;
import android.app.Dialog;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class ShoppingList extends ListActivity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listview = (ListView) findViewById(android.R.id.list);
SQLiteDatabase db;
db = openOrCreateDatabase("Items.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String CREATE_TABLE_ITEMS =
"CREATE TABLE tbl_items ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "item_name TEXT);";
db.execSQL(CREATE_TABLE_ITEMS);
Cursor c = db.query(CREATE_TABLE_ITEMS, null, null, null, null, null, null);
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.rowlayout, c, db, listview);
setListAdapter(adapter);
Button button1main = (Button) findViewById(R.id.add);
button1main.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog additem = new Dialog(ShoppingList.this);
additem.setContentView(R.layout.maindialog);
final EditText et = (EditText)additem.findViewById(R.id.edittext);
additem.setTitle("Type your item");
additem.setCancelable(true);
et.setHint("Type the name of an item...");
Button button = (Button) additem.findViewById(R.id.cancel);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
additem.dismiss();
}
});
additem.show();
Button ok = (Button) additem.findViewById(R.id.ok);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String text = et.getText().toString();
additem.dismiss();
et.setText("");
}
});
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前没有使用过
SimpleCursorAdapter
,但是 文档指出构造函数是:但是你的对构造函数的调用会传入
SQLiteDatabase
来代替String
数组:I've not used a
SimpleCursorAdapter
before, but the documentation states that the constructor is:however your call to the constructor passes in an
SQLiteDatabase
in place of theString
array: