0
SimpleCursorAdapter를 사용할 때 생성자 SimpleCursorAdapter (ShoppingList, int, Cursor, SQLiteDatabase, ListView)는 Eclipse가 정의하지 않습니다. 생성자는 것을 나는 SimpleCursorAdapter
전에 사용하지 않는 한SimpleCursorAdapter (ShoppingList, int, Cursor, SQLiteDatabase, ListView) 생성자가 정의되지 않았습니다.
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("");
}
});
}
});
}
}
문자열과 int에서 무엇을 넣을 것인가의 예가 무엇입니까? – Cg2916
@ Cg2916 [메모장 튜토리얼] (http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html)을 읽고 예를 들어 –
예. 그러나 이제는 nullpointerexception이 발생합니다 :'Cursor c = (Cursor) db.selectAll();'내 db를 다음과 같이 정의합니다 :'final DataHelper db = null;' – Cg2916