MainActivity.java:
private void displayListView() {
cursor = myDatabase.getJoinedInfo(etSearch.getText().toString());
String[] columns = new String[] { myDatabase.RE_VALUE,
myDatabase.GL_VALUE, myDatabase.KE_VALUE };
int[] to = new int[] { R.id.tvHiragana, R.id.tvMeaning, R.id.tvKanji };
dataAdapter = new SimpleCursorAdapter(this, R.layout.wordonlist,
cursor, columns, to, 0);
ListView listView = (ListView) findViewById(R.id.lvWordlist);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
}
我的数据库.java:
public static final String GL_TABLE="gloss";
public static final String GL_ID="id";
public static final String GL_LANG="lang";
public static final String GL_VALUE="value";
public static final String KE_ID="id";
public static final String KE_VALUE="value";
public static final String RE_ID="id";
public static final String RE_VALUE="value";
public static final String LOG_TAG="myLogs";
public Cursor getJoinedInfo(String lookingFor)
{
Log.d(LOG_TAG, "DB: looking up info");
SQLiteDatabase db=getReadableDatabase();
Cursor cursor;
String query;
query="SELECT " +
" e.id AS _id," +
" ke.id AS _id," +
" ke.fk," +
" ke.value," +
" re.id AS _id," +
" re.fk," +
" re.value," +
" s.id AS _id," +
" s.fk," +
" g.id AS _id," +
" g.fk," +
" g.lang," +
" g.value" +
" FROM entry e" +
" INNER JOIN k_ele ke ON e.id = ke.fk" +
" INNER JOIN r_ele re ON e.id = re.fk" +
" INNER JOIN sense s ON e.id = s.fk" +
" INNER JOIN gloss g ON s.id = g.fk" +
" WHERE g.value like '%"+lookingFor+"%' LIMIT 20";
Log.d(LOG_TAG, "DB: query = \n" + query.replace(", ",",\n "));
cursor=db.rawQuery(query,null);
Log.d(LOG_TAG, "DB: query complete");
return cursor;
}
我有 5 张桌子。其中 3 个具有名称为“值”的列。光标只取一个表的“值”而忽略其他表。并且与搜索字符串匹配的所有值都是相似的!请就如何解决这个问题提出一些建议。