Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old December 9th, 2012, 11:07 PM   #1 (permalink)
Member
Thread Author (OP)
 
Join Date: Dec 2011
Location: chennai
Posts: 158
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default add limited product quantity to cart in android

I have developed one android native app.

Here i have to add the limited number of products quantity only add to cart inandroid app.

For eg:

i have to add one product and enter quantity is 3 after that add another product and enter the quantity like 2 after that i have to add another product means that product is doesn't add to cart.how can i do .i have to add the product quantity size is 5 or less than 5 .please help me

I have successfully developed all product is add to cart.

This is my code:
[HIGH]
public class SingleMenuItem extends Activity {
static final String KEY_TITLE = "Name";
static final String KEY_COST = "Price";
static final String KEY_TOTAL = "total";
static final String KEY_QTY = "qty";
static final String KEY_THUMB_URL = "Image";
private EditText edit_qty_code;
private TextView txt_total;
private TextView text_cost_code;
private double itemamount = 0;
private double itemquantity = 0;
String mTitle, mQty, mCost, mTotal;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single);

Intent in = getIntent();
String title = in.getStringExtra(KEY_TITLE);
String thumb_url = in.getStringExtra(KEY_THUMB_URL);
String cost = in.getStringExtra(KEY_COST);
String total = in.getStringExtra(KEY_TOTAL);

ImageLoader imageLoader = new ImageLoader(getApplicationContext());

ImageView imgv = (ImageView) findViewById(R.id.single_thumb);
final TextView txttitle = (TextView) findViewById(R.id.single_title);
TextView txtheader = (TextView) findViewById(R.id.actionbar);
text_cost_code = (TextView) findViewById(R.id.single_cost);
edit_qty_code = (EditText) findViewById(R.id.single_qty);
edit_qty_code.setText("1");
txt_total = (TextView) findViewById(R.id.single_total);

txttitle.setText(title);
txtheader.setText(title);
text_cost_code.setText(cost);
txt_total.setText(total);
imageLoader.DisplayImage(thumb_url, imgv);

itemamount = Double.parseDouble(text_cost_code.getText().toStri ng());

txt_total.setText(Double.toString(itemamount));

edit_qty_code.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
if (!edit_qty_code.getText().toString().equals("")
|| !edit_qty_code.getText().toString().equals("")) {
itemquantity = Double.parseDouble(edit_qty_code.getText()
.toString());
itemamount = Double.parseDouble(text_cost_code.getText()
.toString());
txt_total.setText(Double
.toString(itemquantity * itemamount));
} else {
txt_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) {

}
});

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(
SingleMenuItem.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();

}
});

ImageButton mImgViewCart = (ImageButton) findViewById(R.id.img_view);
mImgViewCart.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mInViewCart = new Intent(SingleMenuItem.this,
ViewCartActivity.class);
startActivity(mInViewCart);
}
});
[/HIGH]

I have to add the product quantity size is equal to 5 or less than 5 only.otherwise have to display only 5 products only allowed to cart on alert dialog.

Advertisements
krishnaveni is offline  
Reply With Quote
sponsored links
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:25 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.