1

我试图从我的 sqlite 数据库中的最后一行获取一个值,并将其用于我的主要活动中的乘法和除法,以获得特定的结果。但我得到的乘法结果为 0,除法结果为“无穷大”。谁能帮忙!!

这是代码

 food.java (main activity)
    {

               //user inputs
                ETRate = (EditText)findViewById(R.id.ETRate);
        ETFoodQty =(EditText)findViewById(R.id.ETFoodQty;
                ETRate.setOnFocusChangeListener(this);
        ETFoodQty.setOnFocusChangeListener(this);

                FoodStorage foodGetInfo = new FoosStorage(this);
            foodGetInfo.open();
            foodGetInfo.getAvgTotal(this);
            foodGetInfo.close();
                chkLastTotal1.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                isChkLastTotal1=true;
            }
        });


public void onFocusChange(View predictionFocusView, boolean hasPredictionETFocus) 
    {
        if(ETRate.isFocused())
                    {
                        if(foodQty!=0) //here I get rate =0
                        {
                            rate =(long) (lastTotal*foodQty);
                            setRate(rate);
                            ETRate.setText(String.valueOf(rate));

                        }
                    }
                    else if(foodQty.isFocused()) //Here I get foodQty = infinity
                    {
                        if(rate!=0)
                        {
                            foodQty =rate/avgtotal;
                            setPredictFoodQty(foodQty);
                            ETfoodQty.setText(String.valueOf(foodQty));
                        }
    }

    foodStorage.java (database file)

        public void getAvgtotal(food pd) 
            {

                String [] columns = new String[]{KEY_ROW_ID, KEY_RATE, KEY_FOOD_QTY, KEY_FOOD_PRICE, KEY_QUALITY, KEY_TOTAL, KEY_DATE,KEY_GRADE};

                if(pd.isChkLastTotal1()==true)
                {

                    Cursor c= ourDatabase.rawQuery("SELECT * FROM food_table ORDER BY _id DESC LIMIT 1", null);
                    c.moveToFirst();
                    if(c!=null && c.getCount()>0)
                    {
                    c.moveToLast();
                    String getLastTotal =c.getString(5);
                    food myFoodInfo = new Food();  
          myFoodInfo.setavgTotal(Double.parseDouble(getLastTotal));
                    }
                    c.close();
                }


                }
4

1 回答 1

0

这里

food myFoodInfo = new Food();  
myFoodInfo.setavgTotal(Double.parseDouble(getLastTotal));

您正在创建新的 Food 对象

为什么不将值设置为 pd 在此处传递:

public void getAvgtotal(food pd) 
于 2013-07-20T12:44:23.027 回答