mercredi 9 mars 2016

How to use values from cursor - android

I have this query and cursor with 4 values. Now I would like to use each of this values to calculate something.

How should I use this values to calculate price (need to get values price1, price2, price3, price4 and multiply it with getResult())?

Should I create new method or calculate inside this one(getParsedPrice)?

Here is the code.

//calculate mass
    public double getResult() {
        double log_length, log_diameter, length, diameter, result;
        log_length = Integer.parseInt(getLength().toString());
        log_diameter = Integer.parseInt(getDiameter().toString());
        length = log_length / 100;
        diameter = log_diameter * log_diameter * 3.14159265;
        result = length * diameter / 40000;
        return result;
    }

    //get prices from Price
    public void  getParsedPrice() {
        try {
        Cursor cursor = db.query("Price", new String[]{"price_stump_kn", "price_stump_eur", "road_price_kn", "road_price_eur"}, "sort = ? AND grade = ? AND length = ? AND diameter BETWEEN diameter_dg AND diameter_gg",
                new String[]{getSort_id(), getGrade(), getLength(), getDiameter()}, null, null, null);
            System.out.print("result" + cursor.toString());
        if (cursor.getCount() > 0) {
             while (cursor.moveToNext()) {
                 double price1 = Double.parseDouble(cursor.getString(0));
                 double price2 = Double.parseDouble(cursor.getString(1));
                 double price3 = Double.parseDouble(cursor.getString(2));
                 double price4 = Double.parseDouble(cursor.getString(3));
             }
        }


        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    //Multiply getResult() with price
    public double calculatePrice() {
        double price, parsedPrice;
        price = getResult() * getParsedPrice();
    }

Aucun commentaire:

Enregistrer un commentaire