Hi I want to show database from a table by select columns and put the data into 2 different listView, no problem getting the data by select columns, but only 1 listView showing the data, the other listView showing blank. No error showed. I've tried to switch the adapter / listView to the works one, and no problem in getting the table. So how can I see where the problem is, sorry if it shows a lot of code, just want to make it clear. Please help me, Thank you.
Here is my fragment showing the 2 listView
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Context context = getActivity();
View v = inflater.inflate(R.layout.fragment_inspection_ss_copy, container, false);
databaseHandler = new DatabaseHandler(getActivity());
lv_gardu_awal = (ListView) v.findViewById(R.id.listviewgarduawal);
listItem = databaseHandler.getInspectionSSItemsDetails();
adapter_awal = new ItemListAdapterInspectionSS(getActivity(), listItem);
lv_gardu_awal.setAdapter(adapter_awal);
lv_gardu_pengukuran = (ListView) v.findViewById(R.id.listviewgardupengukuran);
listItem = databaseHandler.getInspectionSS4ItemsDetails();
adapter_pengukuran = new ItemListAdapterInspectionSS4(getActivity(), listItem);
lv_gardu_pengukuran.setAdapter(adapter_pengukuran);
return v;
}
@Override
public void onResume() {
super.onResume();
listItem.clear();
listItem.addAll(databaseHandler.getInspectionSSItemsDetails());
adapter_awal.notifyDataSetChanged();
listItem.addAll(databaseHandler.getInspectionSS4ItemsDetails());
adapter_pengukuran.notifyDataSetChanged();
}
@Override
public void onPause() {
super.onPause();
listItem.clear();
listItem.addAll(databaseHandler.getInspectionSSItemsDetails());
adapter_awal.notifyDataSetChanged();
listItem.addAll(databaseHandler.getInspectionSS4ItemsDetails());
adapter_pengukuran.notifyDataSetChanged();
}
Here is the adapter that now showing the database
public class ItemListAdapterInspectionSS4 extends BaseAdapter {
private List<ItemsDetails> list;
private LayoutInflater inflater;
private DatabaseHandler handler;
private ItemsDetails itemsDetails;
private TextView COL_ID;
private TextView COL_LWBP_MEASUREMENT_PHASE_R_MAIN ;
private TextView COL_LWBP_MEASUREMENT_PHASE_S_MAIN ;
private TextView COL_LWBP_MEASUREMENT_PHASE_T_MAIN ;
private TextView COL_LWBP_MEASUREMENT_PHASE_N_MAIN ;
public ItemListAdapterInspectionSS4(Activity activity, List<ItemsDetails> list) {
this.list = list;
//this.ACTION = action;
this.activity = activity;
this.inflater = LayoutInflater.from(activity);
handler = new DatabaseHandler(activity);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
//return list.get(position);
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
//return position;
}
@Override
public View getView(int position, View view, ViewGroup root) {
if (view == null) {
view = inflater.inflate(R.layout.listview_item_inspection_ss_4, root, false);
}
LinearLayout mainLayout = (LinearLayout) view.findViewById(R.id.main_layout);
COL_ID = (TextView) view.findViewById(R.id.COL_ID);
COL_LWBP_MEASUREMENT_PHASE_R_MAIN = (TextView) view.findViewById(R.id.COL_LWBP_MEASUREMENT_PHASE_R_MAIN);
COL_LWBP_MEASUREMENT_PHASE_S_MAIN = (TextView) view.findViewById(R.id.COL_LWBP_MEASUREMENT_PHASE_S_MAIN);
COL_LWBP_MEASUREMENT_PHASE_T_MAIN = (TextView) view.findViewById(R.id. COL_LWBP_MEASUREMENT_PHASE_T_MAIN);
COL_LWBP_MEASUREMENT_PHASE_N_MAIN = (TextView) view.findViewById(R.id.COL_LWBP_MEASUREMENT_PHASE_N_MAIN);
COL_ID.setText("" + (position + 1));
COL_LWBP_MEASUREMENT_PHASE_R_MAIN.setText("" + list.get(position).getfasaRUtamaLWBP());
COL_LWBP_MEASUREMENT_PHASE_S_MAIN.setText("" + list.get(position).getfasaSUtamaLWBP());
COL_LWBP_MEASUREMENT_PHASE_T_MAIN.setText("" + list.get(position).getfasaTUtamaLWBP());
COL_LWBP_MEASUREMENT_PHASE_N_MAIN.setText("" + list.get(position).getfasaNUtamaLWBP());
return view;
}
}
This adapter works fine
@Override
public View getView(int position, View view, ViewGroup root) {
if (view == null) {
view = inflater.inflate(R.layout.listview_item_inspection_ss, root, false);
}
LinearLayout mainLayout = (LinearLayout) view.findViewById(R.id.main_layout);
COL_ID = (TextView) view.findViewById(R.id.COL_ID);
COL_LOCATION_ID = (TextView) view.findViewById(R.id.COL_LOCATION_ID);
COL_SECTION_ID = (TextView) view.findViewById(R.id.COL_SECTION_ID);
COL_INSPECTION_DATE = (TextView) view.findViewById(R.id.COL_INSPECTION_DATE);
COL_INSPECTION_TYPE_ID = (TextView) view.findViewById(R.id.COL_INSPECTION_TYPE_ID);
COL_ID.setText("" + (position + 1));
COL_LOCATION_ID.setText("" + handler.getCategoryFromID("" + list.get(position).getunitID()).getName());
COL_SECTION_ID.setText("" + handler.getGarduFromID("" + list.get(position).getgarduID()).getName());
COL_INSPECTION_DATE.setText("" + list.get(position).gettanggalInspeksi());
COL_INSPECTION_TYPE_ID.setText("" + handler.getTipeInspeksiFromID("" + list.get(position).gettipeInspeksiID()).getName());
return view;
}
Here is my database
String CREATE_INSPECTION_SS_TABLES = " CREATE TABLE IF NOT EXISTS " + INSPECTIONS_SS_TABLE_NAME
+ "(" + COL_ID + " INTEGER PRIMARY KEY, " +
COL_LOCATION_ID + " INTEGER, " +
COL_SECTION_ID + " INTEGER, " +
COL_INSPECTION_DATE + " TEXT, " +
COL_INSPECTION_TYPE_ID + " INTEGER, " +
COL_LWBP_MEASUREMENT_PHASE_R_MAIN + " INTEGER, " +
COL_LWBP_MEASUREMENT_PHASE_S_MAIN + " INTEGER, " +
COL_LWBP_MEASUREMENT_PHASE_T_MAIN + " INTEGER, " +
COL_LWBP_MEASUREMENT_PHASE_N_MAIN + " INTEGER " +
")";
Here is how I get the columns
public List<ItemsDetails> getInspectionSSItemsDetails() {
List<ItemsDetails> detailsList = new ArrayList<ItemsDetails>();
String selectQuery = "SELECT _id, location_id, section_id, inspection_date, inspection_type_id FROM " + INSPECTIONS_SS_TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
try {
ItemsDetails details = new ItemsDetails();
details.setId(cursor.getInt(0));
details.setunitID(cursor.getInt(1));
details.setgarduID(cursor.getInt(2));
details.settanggalInspeksi(cursor.getString(3));
details.settipeInspeksiID(cursor.getInt(4));
detailsList.add(details);
} catch (Exception e) {
e.printStackTrace();
}
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return detailsList;
}
public List<ItemsDetails> getInspectionSS4ItemsDetails() {
List<ItemsDetails> detailsList = new ArrayList<ItemsDetails>();
String selectQuery = "SELECT _id, lwbp_measurement_phase_r_main, lwbp_measurement_phase_s_main, lwbp_measurement_phase_t_main, lwbp_measurement_phase_n_main FROM " + INSPECTIONS_SS_TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
try {
ItemsDetails details = new ItemsDetails();
details.setId(cursor.getInt(cursor.getColumnIndex("_id")));
details.setfasaRUtamaLWBP(cursor.getString(cursor.getColumnIndex("lwbp_measurement_phase_r_main")));
details.setfasaSUtamaLWBP(cursor.getString(cursor.getColumnIndex("lwbp_measurement_phase_s_main")));
details.setfasaTUtamaLWBP(cursor.getString(cursor.getColumnIndex("lwbp_measurement_phase_t_main")));
details.setfasaNUtamaLWBP(cursor.getString(cursor.getColumnIndex("lwbp_measurement_phase_n_main")));
detailsList.add(details);
} catch (Exception e) {
e.printStackTrace();
}
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return detailsList;
}
Aucun commentaire:
Enregistrer un commentaire