android - 总计无法解析为 Android 中的类型

标签 android

我正在尝试从 Adapter 类到 Activity 类获取 total 值,但我收到一条错误消息:

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

    }
    }

} 

最佳答案

您无法从总 TextView 中获取文本值。

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

}

关于android - 总计无法解析为 Android 中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15717948/

相关文章:

java - Firebase 实时数据库更新数据 - Android Java

android - 在 onSaveInstanceState 之后无法使用 BottomsheetDialogFragment 执行此操作吗?

android - rawQuery 中的 ORMLite 别名

android - 关闭 Activity fragment 内的 Bottom Sheet

android - 重置 Android 对话框

java - Apache POI 和 Aspose?

android - 为 Android 构建 OpenJPEG

Android Debug模式性能

Android模拟器错误-ddmlib错误

android - Android studio 中的空测试套件运行测试并覆盖