android - 如何在android中显示数据库中的所有行

标签 android database sqlite

如何在android中显示数据库中的所有行。在下面的代码中它只显示数据库表中的最后一行。请帮助我。

            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]

最佳答案

下面的代码是获取数据库中的所有列表。它适用于我。

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

关于android - 如何在android中显示数据库中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24259919/

相关文章:

android - 在图像android的一半高度之间显示后退和下一步按钮

android - Android 布局 xml 中的注释

android - 如何在 android 中以编程方式获得七段时钟?

java - 第一次调用一个方法,当数据有变化时再次调用该方法

java - 如何检查值是否存在/为什么 ResultSet 在 SQLite 中关闭?

android - 在哪里可以找到音量图标

php - MySQL 最后一个条目 PHP 按日期排序

c# - 如何在一行中获取特定用户的数据

SQLite复合键(2个外键)链接表

android - (21) 使用 NULL 预准备语句调用 API