add limited product to cart in android
- by user1859172
I have to develop one shopping cart app.
Here i have to add the product only 5.otherwise have to display the message on alert dialog like 5 products only allowed.
How can i develop this.please help me
This is my code:
ImageButton mImgAddCart = (ImageButton) findViewById(R.id.img_add);
mImgAddCart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mTitle = txttitle.getText().toString();
mCost = text_cost_code.getText().toString();
mCost = mCost.replace("From ", "");
mTotal = txt_total.getText().toString();
mTotal = mTotal.replace("From ", "");
mQty = edit_qty_code.getText().toString();
if (Constants.mItem_Detail.size() <= 0) {
HashMap<String, String> mTempObj = new HashMap<String, String>();
mTempObj.put(KEY_TITLE, mTitle);
mTempObj.put(KEY_QTY, mQty);
mTempObj.put(KEY_COST, mCost);
mTempObj.put(KEY_TOTAL, mTotal);
Constants.mItem_Detail.add(mTempObj);
} else {
for (int i = 0; i < Constants.mItem_Detail.size(); i++) {
if (Constants.mItem_Detail.get(i).get(KEY_TITLE)
.equals(mTitle)) {
Constants.mItem_Detail.remove(i);
break;
} else {
}
}
HashMap<String, String> mTempObj = new HashMap<String, String>();
mTempObj.put(KEY_TITLE, mTitle);
mTempObj.put(KEY_QTY, mQty);
mTempObj.put(KEY_COST, mCost);
mTempObj.put(KEY_TOTAL, mTotal);
Constants.mItem_Detail.add(mTempObj);
}
AlertDialog.Builder alertdialog = new AlertDialog.Builder(
Small.this);
alertdialog.setTitle(getResources()
.getString(R.string.app_name));
alertdialog.setMessage("Add in ViewCart");
alertdialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
finish();
}
});
alertdialog.show();
}
});
How can i set the condition for this.please give me one idea.