我对如何将两个单独的数据库查询组合到一个 listView 中感到很困惑。
目前,我的 listView 由以下适配器填充,该适配器在我的数据库中查询损坏的组件表并提供某个位置的损坏组件列表:
private class MyListAdapter extends ResourceCursorAdapter {
// In your ListActivity class, create a new inner class that extends ResourceCursorAdapter.
//This inner class is the custom CursorAdapter we will use to manage how data is bound to a list item:
public MyListAdapter(Context context, Cursor cursor) {
super(context, R.layout.row_location, cursor);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView text_first_line = (TextView) view.findViewById(R.id.location_row_item_main_text);
TextView text_second_line = (TextView) view.findViewById(R.id.location_row_item_secondary_text);
ImageView flagIcon = (ImageView) view.findViewById(R.id.flagIcon);
String row_text_component = cursor.getString(cursor.getColumnIndex(RMDbAdapter.COMPONENT));
String row_text_position = ", Position " + cursor.getString(cursor.getColumnIndex(RMDbAdapter.POSITION));
if(row_text_position.equals(", Position Not Applicable")){
row_text_position = "";
}
String row_text_action = " - " + cursor.getString(cursor.getColumnIndex(RMDbAdapter.ACTION_REQUIRED));
text_first_line.setText(row_text_component + row_text_position + row_text_action);
text_second_line.setText("Dexion Speedlock, S Duty, 3000mm");
String risk = cursor.getString(cursor.getColumnIndex(RMDbAdapter.RISK));
if (risk.equals("Red Risk")){
flagIcon.setImageResource(R.drawable.red_flag);
}
else if (risk.equals("Green Risk")){
flagIcon.setImageResource(R.drawable.green_flag);
}
else if (risk.equals("No Risk")){
flagIcon.setImageResource(R.drawable.note);
}
}
}
当我在活动开始时调用以下命令时会触发此事件:
private void setAdapter(){
// Get a Cursor for the list items
Cursor listComponentCursor = rmDbHelper.fetchDamagedComponentsForLocation(locationId);
componentCursorSize = listComponentCursor.getCount();
startManagingCursor(listComponentCursor);
// set the custom list adapter
setListAdapter(new MyListAdapter(this, listComponentCursor));
}
因此,我还想在单独的表(这次是问题表)上创建第二个查询,并将其添加到损坏组件列表下的 listView 中。
从多个表中读取此Listview?,我相信我应该使用 Join或Merge 游标。但是,根据我的研究,我仍然不知道如何将这两个概念集成到我的代码中。
谁能指出我正确的方向?