我正在尝试从 Adapter 类到 Activity 类获取总价值,但我收到一条错误消息:
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);
}
}
}