lv_gardu_pengukuran.setAdapter(adapter_pengukuran);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_awal = databaseHandler.getInspectionSSItemsDetails();
adapter_awal = new ItemListAdapterInspectionSS(getActivity(), listItem_awal);
lv_gardu_awal.setAdapter(adapter_awal);
lv_gardu_pengukuran = (ListView) v.findViewById(R.id.listviewgardupengukuran);
listItem_pengukuran = databaseHandler.getInspectionSS4ItemsDetails();
adapter_pengukuran = new ItemListAdapterInspectionSS4(getActivity(), listItem_pengukuran);
lv_gardu_pengukuran.setAdapter(adapter_pengukuran);
return v;
}
@Override
public void onResume() {
super.onResume();
listItem_awal.clear();
listItem_awal.addAll(databaseHandler.getInspectionSSItemsDetails());
adapter_awal.notifyDataSetChanged();
listItem_pengukuran.clear();
listItem_pengukuran.addAll(databaseHandler.getInspectionSS4ItemsDetails());
adapter_pengukuran.notifyDataSetChanged();
}
@Override
public void onPause() {
super.onPause();
listItem_awal.clear();
listItem_awal.addAll(databaseHandler.getInspectionSSItemsDetails());
adapter_awal.notifyDataSetChanged();
listItem_pengukuran.clear();
listItem_pengukuran.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;
}
Here is my layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout_tab_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4"
android:padding="8dp">
<LinearLayout
android:id="@+id/layout_sub_parent_1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_weight="1"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/title_number"
android:textStyle="bold" />
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_LOCATION_ID"
android:textStyle="bold" />
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_SECTION_ID"
android:textStyle="bold" />
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_INSPECTION_DATE"
android:textStyle="bold" />
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_INSPECTION_TYPE_ID"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listviewgarduawal"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_sub_parent_4"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_weight="1"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/title_number"
android:textStyle="bold" />
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_LWBP_MEASUREMENT_PHASE_R_MAIN"
android:textStyle="bold" />
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_LWBP_MEASUREMENT_PHASE_S_MAIN"
android:textStyle="bold" />
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_LWBP_MEASUREMENT_PHASE_T_MAIN"
android:textStyle="bold" />
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="@string/COL_LWBP_MEASUREMENT_PHASE_N_MAIN"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listviewgardupengukuran"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
<!-- end here -->
</ScrollView>
My List Item Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/COL_ID"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold" />
<TextView
android:id="@+id/COL_LWBP_MEASUREMENT_PHASE_R_MAIN"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold" />
<TextView
android:id="@+id/COL_LWBP_MEASUREMENT_PHASE_S_MAIN"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold" />
<TextView
android:id="@+id/COL_LWBP_MEASUREMENT_PHASE_T_MAIN"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold" />
<TextView
android:id="@+id/COL_LWBP_MEASUREMENT_PHASE_N_MAIN"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold" />
</LinearLayout>