検索ボタンをクリックして SQLite データベースからデータを取得し、それをアプリに表示するにはどうすればよいですか?
マイ アクティビティ:
public class EKaDEMActivity extends Activity implements OnClickListener {
//EditText ET;
public static final String KEY_ROWID = "Dic_id";
public static final String colID="_id";
public static final String colKD="KD_word";
public static final String colENG="ENG_word";
public static final String colMAL="Malay_word";
public static final String colAudio="KD_audio";
private static final String dbName="Dictionary";
private static final String dbTable="tbl_Dictionary";
private static final int dbVersion = 2;
static final String viewEmps="ViewEmps";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton button = (ImageButton)findViewById(R.id.button_one);
button.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
EditText ET = (EditText) findViewById(R.id.AutoTextBox);
ET = (EditText) findViewById(R.id.AutoTextBox);
String s = ET.getText().toString();
TextView TV = (TextView)findViewById(R.id.DefTextView);
TV.setText("Welcome Using Kadazandusun-English-Malay Mobile Dictionary Application");
boolean r = s.contentEquals("dog");
if (r == true)
{
String str = " M: Anging \n\n" + " KD: Tasu ";
TextView text = (TextView)findViewById(R.id.DefTextView);
text.setText(str);
}
else
{
TV.setText(" Word not found");
}
}
}
これは私の Database.java です
public static final String KEY_ROWID = "Dic_id";
public static final String colID="_id";
public static final String colKD="KD_word";
public static final String colENG="ENG_word";
public static final String colMAL="Malay_word";
public static final String colAudio="KD_audio";
private static final String dbName="Dictionary";
private static final String dbTable="tbl_Dictionary";
private static final int dbVersion = 1;
static final String viewEmps="ViewEmps";
public Database(Context context, String name, CursorFactory factory,
int version) {
super(context, dbName, null, dbVersion);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + dbTable + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
colKD + " TEXT NOT NULL, " +
colENG + " TEXT NOT NULL, " +
colMAL + " TEXT NOT NULL, );");
db.execSQL("CREATE VIEW "+viewEmps+
" AS SELECT "+dbTable+"."+colID+" AS _id,"+
" "+dbTable+"."+colKD+","+
" "+dbTable+"."+colENG+","+
" "+dbTable+"."+colMAL+""+
" FROM "+dbTable
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS "+ dbTable);
onCreate(db);
}
void AddWord(Word wrd)
{
SQLiteDatabase db= this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(colKD, wrd.getKD());
cv.put(colENG, wrd.getENG());
cv.put(colMAL, wrd.getMAL());
//cv.put(colDept,2);
db.insert(dbTable, colKD, cv);
db.close();
}
public int UpdateWrd(Word wrd)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(colKD, wrd.getKD());
cv.put(colENG, wrd.getENG());
cv.put(colMAL, wrd.getMAL());
return db.update(dbTable, cv, colID+"=?", new String []{String.valueOf(wrd.getID())});
}
public void DeleteWrd(Word wrd)
{
SQLiteDatabase db=this.getWritableDatabase();
db.delete(dbTable,colID+"=?", new String [] {String.valueOf(wrd.getID())});
db.close();
}
Cursor getWord()
{
SQLiteDatabase db=this.getWritableDatabase();
Cursor cur= db.rawQuery("SELECT * FROM "+viewEmps,null);
return cur;
}
}