从表中读取列到2个不同的列表视图,只有1个listview工作(Read columns from table into 2 different list view only 1 listview w

编程入门 行业动态 更新时间:2024-10-11 07:33:20
从表中读取列到2个不同的列表视图,只有1个listview工作(Read columns from table into 2 different list view only 1 listview working)

lv_gardu_pengukuran.setAdapter(adapter_pengukuran);您好我想通过选择列从表中显示数据库并将数据放入2个不同的listView,没有问题通过选择列获取数据,但只有1个listView显示数据,另一个listView显示空白。 没有错误显示。 我试图将适配器/ listView切换到工作,并且没有问题获取表。 那么我怎么能看到问题出在哪里,对不起,如果它显示了很多代码,只是想说清楚。 请帮帮我,谢谢。

这是我的片段显示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(); }

这是现在显示数据库的适配器

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; }

}

这个适配器工作正常

@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; }

这是我的数据库

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 " + ")";

这是我如何得到列

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; }

这是我的布局

<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>

我的清单项目布局

<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>

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>

最满意答案

如果没有一些技巧,你不能在同一页面上放置两个列表视图。 每个人都想接管屏幕和所有滚动事件。 您可能希望创建一个自定义适配器,将数据合并到一个列表视图中,或者在滚动视图中放置两个动态线性布局。

You can't put two listviews on the same page without some tricks. Each one will want to take over the screen and all the scroll events. You may want to create a custom adapter that combines the data into one listview or puts two dynamic linear layouts inside a scrollview.

更多推荐

本文发布于:2023-07-27 15:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   列表   工作   listview   Read

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!