Reputation: 59
how to display all rows in database in android.in the following code it is displaying only the last row in database table.please help me.
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);
}
i want to display all the rows in database table.but it is displaying in logcat and in device it is showing only last row in table.so please help me. ![enter image description here][1]
Upvotes: 1
Views: 193
Reputation: 59
the following code is to get all the list in database.it works for me.
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);
}
Upvotes: 1