how to show all added items into another activity, like: AddtoCart and ViewCart Functionality
Posted
by
Stanley
on Stack Overflow
See other posts from Stack Overflow
or by Stanley
Published on 2012-10-26T04:58:16Z
Indexed on
2012/10/26
5:00 UTC
Read the original article
Hit count: 207
i am trying to make a shopping cart app, allowing user to choose category then select item to purchase, once user will click on any item to purchase, then showing that selected item into another activity with item image, name, cost, qty (to accept by user) and also providing add to cart functionality, now i want whenever user will click on Add to Cart button, then selected item need to show in ViewCart Activity, so here i am placing my AddtoCart Activity code, please tell me what i need to write to show added item(s) into ViewCart Category just like in shopping cart, In ViewCart activity i just want to show item title, cost and qty (entered by user):-
public class AddtoCart extends Activity{
static final String KEY_TITLE = "title";
static final String KEY_COST = "cost";
static final String KEY_THUMB_URL = "imageUri";
@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);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());
ImageView imgv = (ImageView) findViewById(R.id.single_thumb);
TextView txttitle = (TextView) findViewById(R.id.single_title);
TextView txtcost = (TextView) findViewById(R.id.single_cost);
txttitle.setText(title);
txtcost.setText(cost);
imageLoader.DisplayImage(thumb_url, imgv);
// Save a reference to the quantity edit text
final EditText editTextQuantity = (EditText) findViewById(R.id.edit_qty);
ImageButton addToCartButton = (ImageButton) findViewById(R.id.img_add);
addToCartButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Check to see that a valid quantity was entered
int quantity = 0;
try {
quantity = Integer.parseInt(editTextQuantity.getText()
.toString());
if (quantity <= 0) {
Toast.makeText(getBaseContext(),
"Please enter a quantity of 1 or higher",
Toast.LENGTH_SHORT).show();
return;
}
} catch (Exception e) {
Toast.makeText(getBaseContext(),
"Please enter a numeric quantity",
Toast.LENGTH_SHORT).show();
return;
}
// Close the activity
finish();
}
});
}}
© Stack Overflow or respective owner