I am quite confused about how to combine two separate database queries into one listView.
Currently, my listView is populated by the following adapter which queries the damaged component table in my database and provides a list of damaged components for a certain location:
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);
}
}
}
This is triggered when I call the following when the activity is started:
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));
}
So I would also like to create a second query on a separate table (this time issues table) and add this to the listView under the list of damaged components.
Reading this Listview from multiple tables?, I believe that I should use a Join or Merge cursor. However, from what I have researched I still have no idea how to integrate either concept into my code.
Can anyone point me in the right direction please?