두 개의 개별 데이터베이스 쿼리를 하나의 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 from multiple tables?을 읽으면서 Join 또는 병합 커서를 사용해야한다고 생각합니다. 그러나, 내가 조사한 바에 따르면, 나는 두 코드를 내 코드에 통합하는 방법을 모른다.
누구나 올바른 방향으로 나를 가리킬 수 있습니까?
안녕 toadzky을 던질 수 없기 때문에
2)는
"literal string".equals(variable)
대신variable.equals("literal string")
을하는 것이 좋습니다. 당신이 보는 것은 listView를 채우는 모든 코드입니다 - 나는 newView를 오버라이드하지 않았습니다 (전에 들어 보지 못했습니다). 이 요소에 대해 자세히 설명해 주시겠습니까? 또한 각 테이블마다 다른 열 이름을 사용하여 getItemViewType을 재정의하는 방법에 대한 예가 있습니까? 지금까지 귀하의 도움에 감사드립니다. – ScamparelliCursorAdapter를 사용하여 재정의해야하는 두 가지 메소드 newView 및 bindView가 있습니다. newView는 뷰를 팽창 시키거나 생성한다. bindView는 뷰에 값을 지정합니다. ResourceCursorAdapter 서브 클래스가 당신을 대신해 처리하는 것처럼 보입니다. 해당 하위 클래스를 사용할 특별한 이유가 있습니까? 그렇지 않다면 CursorAdapter를 확장하십시오. – toadzky
코드가 현재 작동하고 있다면 newView가 필요합니까? – Scamparelli