如何在android.in中显示数据库中的所有行,以下代码只显示数据库表中的最后一行。请帮助我。
public void dynamicLayout(String sfixed_AssetDescription ) {
LinearLayout ll=new LinearLayout(this);
View child = getLayoutInflater().inflate(R.layout.fixed_asset_dlayout, null);
TextView dfixed_AssetID = (TextView) child.findViewById(R.id.dfixed_AssetID);
TextView dfixed_AssetDescription = (TextView) child.findViewById(R.id.dfixed_AssetDescription);
TextView dfixed_SuppliersName = (TextView) child.findViewById(R.id.dfixed_SuppliersName);
TextView dfixed_Makemodelotherspec = (TextView) child.findViewById(R.id.dfixed_Makemodelotherspec);
TextView dfixed_PO_no = (TextView) child.findViewById(R.id.dfixed_PO_no);
TextView dfixed_PO_Date = (TextView) child.findViewById(R.id.dfixed_PO_Date);
TextView dfixed_Bill_No = (TextView) child.findViewById(R.id.dfixed_Bill_No);
TextView dfixed_qty = (TextView) child.findViewById(R.id.dfixed_qty);
TextView dfixed_Dateputtouse = (TextView) child.findViewById(R.id.dfixed_Dateputtouse);
TextView dfixed_rateofdescription = (TextView) child.findViewById(R.id.dfixed_rateofdescription);
TextView dfixed_purchasevalue = (TextView) child.findViewById(R.id.dfixed_purchasevalue);
TextView dfixed_salevalue = (TextView) child.findViewById(R.id.dfixed_salevalue);
TextView dfixed_total = (TextView) child.findViewById(R.id.dfixed_total);
Button edit = (Button) child.findViewById(R.id.dfixed_edit);
Button delete = (Button) child.findViewById(R.id.dfixed_delete);
farp=db.getFARDetails();
/*List<String>list=new ArrayList<String>();
for(int i=0;i<farp.size();i++){
//list.add(maap.get(i).getAsset_Name());
farp=db.getFARDetails();
//dfixed_AssetID.setText(farp.get(farp.size()).getAsset_ID());
Log.v("___________________________", "farp.get(i).getAsset_ID()___________"+farp.get(i).getAsset_ID());
// Log.v("___________________________", "farp.get(i).getAsset_ID()___________"+farp);
//dfixed_AssetID.setText(farpojo.getAsset_ID());
//Log.v("___________________________", "farpojo.getAsset_ID()___________"+farpojo.getAsset_ID());
}*/
List<Fixed_asset_register_pojo> f = db.getFARDetails();
//for(int i=0;i<farp.size();i++){
for (Fixed_asset_register_pojo f1 : f) {
dfixed_AssetID.setText(f1.getAsset_ID());
Log.e("LLLLLLLLLLLLLLLLLLLLLLLLLLLL", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFF"+f1.getAsset_ID());
dfixed_AssetDescription.setText(sfixed_AssetDescription);
dfixed_SuppliersName.setText(f1.getSupplier_Name());
dfixed_Makemodelotherspec.setText(f1.getModel_Specifications());
dfixed_PO_no.setText(f1.getPurchase_Order_No());
dfixed_PO_Date.setText(f1.getPurchase_Order_Date());
dfixed_Bill_No.setText(f1.getBill_No());
dfixed_qty.setText(f1.getQuantity());
dfixed_Dateputtouse.setText(f1.getDate_Put_To_Use());
dfixed_rateofdescription.setText(f1.getRate_Of_Depreciation());
dfixed_purchasevalue.setText(f1.getPurchase_Amount());
dfixed_salevalue.setText(f1.getSale_Amount());
dfixed_total.setText(f1.getTotal_Amount());
}
ll.addView(child);
linearLayout.addView(ll);
}
我想显示数据库表中的所有行。但它显示在logcat和设备中,它只显示表中的最后一行。所以请帮助我。 ![在此输入图像说明] [1]
答案 0 :(得分:1)
以下代码是获取database.it中的所有列表。对我来说。
public void dynamicLayout(String sfixed_AssetDescription ) {
List<Fixed_asset_register_pojo> f = db.getFARDetails();
for (Fixed_asset_register_pojo f1 : f) {
View child = getLayoutInflater().inflate(R.layout.fixed_asset_dlayout, null);
TextView dfixed_AssetID = (TextView) child.findViewById(R.id.dfixed_AssetID);
TextView dfixed_AssetDescription = (TextView) child.findViewById(R.id.dfixed_AssetDescription);
TextView dfixed_SuppliersName = (TextView) child.findViewById(R.id.dfixed_SuppliersName);
TextView dfixed_Makemodelotherspec = (TextView) child.findViewById(R.id.dfixed_Makemodelotherspec);
TextView dfixed_PO_no = (TextView) child.findViewById(R.id.dfixed_PO_no);
TextView dfixed_PO_Date = (TextView) child.findViewById(R.id.dfixed_PO_Date);
TextView dfixed_Bill_No = (TextView) child.findViewById(R.id.dfixed_Bill_No);
TextView dfixed_qty = (TextView) child.findViewById(R.id.dfixed_qty);
TextView dfixed_Dateputtouse = (TextView) child.findViewById(R.id.dfixed_Dateputtouse);
TextView dfixed_rateofdescription = (TextView) child.findViewById(R.id.dfixed_rateofdescription);
TextView dfixed_purchasevalue = (TextView) child.findViewById(R.id.dfixed_purchasevalue);
TextView dfixed_salevalue = (TextView) child.findViewById(R.id.dfixed_salevalue);
TextView dfixed_total = (TextView) child.findViewById(R.id.dfixed_total);
Button edit = (Button) child.findViewById(R.id.dfixed_edit);
Button delete = (Button) child.findViewById(R.id.dfixed_delete);
dfixed_AssetID.setText(f1.getAsset_ID());
Log.e("LLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + f1.getAsset_ID());
dfixed_AssetDescription.setText(sfixed_AssetDescription);
dfixed_SuppliersName.setText(f1.getSupplier_Name());
dfixed_Makemodelotherspec.setText(f1.getModel_Specifications());
dfixed_PO_no.setText(f1.getPurchase_Order_No());
dfixed_PO_Date.setText(f1.getPurchase_Order_Date());
dfixed_Bill_No.setText(f1.getBill_No());
dfixed_qty.setText(f1.getQuantity());
dfixed_Dateputtouse.setText(f1.getDate_Put_To_Use());
dfixed_rateofdescription.setText(f1.getRate_Of_Depreciation());
dfixed_purchasevalue.setText(f1.getPurchase_Amount());
dfixed_salevalue.setText(f1.getSale_Amount());
dfixed_total.setText(f1.getTotal_Amount());
linearLayout.addView(child);
}