Android 用の RSS リーダーを作成しています。データベースは私の専門知識ではないため、解決できない特定の問題に直面しました。現在、3 つのテーブル (カテゴリ、リンク、フィード) があります。私の目標は、フィードを複数のカテゴリにリンクすることです。そのため、リンク テーブルを使用しています。私のデータベースは Android ContentProvider (sqlite) であり、次のようになります。
| Categories | | Links | | Feeds |
|------------| |---------| |-------|
| _ID | | Category| | _ID |
| Title | | Feed | | Title |
| URL |
現在、FeedListActivity に次のコードを記述して、リンクとそのフィードのリストを取得しています。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//gets the intent URI to retrieve the Feeds.
Intent intent = getIntent();
if (intent.getData() == null) {
intent.setData(Feeds.CONTENT_URI);
}
// stores the Category id so it knows from what category it came from
mCatId = intent.getIntExtra("catId", -1);
getListView().setOnCreateContextMenuListener(this);
// gets all Links that have the category placed
Cursor links = managedQuery(
Links.CONTENT_URI,
NewsReadUtils.LINK_PROJECTION_STRING,
Links.CATEGORY+ " = "+ mCatId, null, null);
String query = "";
Cursor cursor = null;
if(links.getCount()>0){
// if there are links available try to get them and build a query.
links.moveToFirst();
do{
if (links.isFirst()) {
query = Feeds._ID+ " = "+links.getString(links.getColumnIndex(Links.FEED));
}else{
query += " OR " +Feeds._ID+ " = "+links.getString(links.getColumnIndex(Links.FEED));
}
}while(links.moveToNext());
cursor = managedQuery(getIntent().getData(), PROJECTION ,query, null,
Feeds.DEFAULT_SORT_ORDER);
}
Cursor cursor = managedQuery(getIntent().getData(), PROJECTION ,Feeds._ID+ " = "+ mCatId, null,
Feeds.DEFAULT_SORT_ORDER);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor,
new String[] { Feeds.TITLE }, new int[] { android.R.id.text1 });
setListAdapter(adapter);
}
今私の質問:
このデータベースのレイアウト、コード、またはクエリを最適化して、より効率的な方法でエントリを取得する方法を考えていました。このリンク テーブルまたはリンクを取得するためのクエリは必要ないと考えているためです。それとも私はこれを正しい方法でやっていますか?
ありがとう、
アンテック