2013-03-30 51 views
1

我試圖從適配器類Activity類總獲取價值解析爲一個類型,但我收到一條錯誤消息:總不能在Android的

total cannot be resolved to a type 

    // here i am getting total cannot be resolved to a type 
Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0).get(total)); // total (single) > CartAdapter 

CartAdapter.java:

public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    View vi = convertView; 
    if (convertView == null) 
     vi = inflater.inflate(R.layout.listrow_cart, null); 

    TextView title = (TextView) vi.findViewById(R.id.title); 
    final TextView cost = (TextView) vi.findViewById(R.id.cost); 
    final TextView qty = (TextView) vi.findViewById(R.id.qty); 
    final TextView total = (TextView) vi.findViewById(R.id.total); 


    ImageButton mImgBtnDelete = (ImageButton) vi 
      .findViewById(R.id.mImgBtnDelete); 

    mImgBtnDelete.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      Constants.mItem_Detail.remove(position); 
      notifyDataSetChanged(); 

      Intent mInViewCartRefresh = new Intent(activity, 
        CartActivity.class); 
      activity.startActivity(mInViewCartRefresh); 
      activity.finish(); 
     } 
    }); 

    HashMap<String, String> item = new HashMap<String, String>(); 
    item = Constants.mItem_Detail.get(position); 

    // Setting all values in listview 
    title.setText(item.get(restra.second.erachnida.menus.ProductInformationActivity.KEY_TITLE)); 
    cost.setText(item.get(restra.second.erachnida.menus.ProductInformationActivity.KEY_COST)); 
    qty.setText("1"); 
    qty.addTextChangedListener(new TextWatcher() { 

     public void onTextChanged(CharSequence s, int start, int before, 
       int count) { 
      // TODO Auto-generated method stub 
      if (!qty.getText().toString().equals("") 
        || !qty.getText().toString().equals("")) { 
       int itemquantity = Integer.parseInt(qty.getText() 
         .toString()); 
       double itemamount = Double.parseDouble(cost.getText() 
         .toString()); 
       total.setText(new DecimalFormat("##.##").format(itemamount*itemquantity)); 
      } else { 
       total.setText("0.00"); 
      } 
     } 

     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
      // TODO Auto-generated method stub 

     } 

     public void afterTextChanged(Editable s) { 

     } 
    }); 

CartActivity.java:

 public class CartActivity extends Activity 
    { 

TextView mTxtViewGrandTotal; 
TextView myTextVeiwGrandTotal; 

TextView mItems; 
String mGrandTotal; 
String mTotal; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_cart); 

    ListView mLstView1 = (ListView) findViewById(R.id.listView1); 

    mTxtViewGrandTotal = (TextView) findViewById(R.id.billing_amount); 
    myTextVeiwGrandTotal = (TextView) findViewById(R.id.total_amount); 
    mItems = (TextView) findViewById(R.id.total_items); 

    CartAdapter mViewCartAdpt = new CartAdapter(CartActivity.this); 
    mLstView1.setAdapter(mViewCartAdpt); 


    if (Constants.mItem_Detail.size() > 0) 
    { 
     // here i am getting total cannot be resolved to a type 
     Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0).get(total)); // total (single) > CartAdapter 
     for (int i = 1; i < Constants.mItem_Detail.size(); i++) 
     { 
     mGTotal = mGTotal + Double.parseDouble(Constants.mItem_Detail.get(i).get(total)); // total (all) > CartAdapter 
     } 
     mGrandTotal = String.valueOf(mGTotal); 
     mTxtViewGrandTotal.setText(mGrandTotal); 
     myTextVeiwGrandTotal.setText(mGrandTotal); 
     mTxtViewGrandTotal.setText(new DecimalFormat("##.##").format(mGTotal)); 
     mTotal = String.valueOf(Constants.mItem_Detail.size()); 
     mItems.setText(mTotal); 

    } 
    } 

} 
+0

如果您收到此錯誤?請提到 –

+0

@ ling.si建議您先閱讀完整的問題然後再評論或者投票,看看這裏://這裏我總得到不能解析的類型 Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get 0)獲得(總)); // total(single)> CartAdapter – Babu

+0

因爲你的代碼總數不是一個變量 –

回答

0

它看起來總是您的適配器類中的textview。所以試試這個:

Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0).get(total.getText().toString())); 
+0

同樣的問題總數不能解析爲一個變量 – Babu

1

你沒有從文本文本視圖中獲取文本值。

TextView total =(TextView)vi.findViewById(R.id.total);

total.getText()。的toString()

if (Constants.mItem_Detail.size() > 0) 
{ 
    // here i am getting total cannot be resolved to a type 
    Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0).get(total.getText().toString())); // total (single) > CartAdapter 
    for (int i = 1; i < Constants.mItem_Detail.size(); i++) 
    { 
    mGTotal = mGTotal + Double.parseDouble(Constants.mItem_Detail.get(i).get(total.getText().toString())); // total (all) > CartAdapter 
    } 
    mGrandTotal = String.valueOf(mGTotal); 
    mTxtViewGrandTotal.setText(mGrandTotal); 
    myTextVeiwGrandTotal.setText(mGrandTotal); 
    mTxtViewGrandTotal.setText(new DecimalFormat("##.##").format(mGTotal)); 
    mTotal = String.valueOf(Constants.mItem_Detail.size()); 
    mItems.setText(mTotal); 

}