i am making an app, in which i am fetching data into listview using json parser, then showing selected listview item row into another activity with item details (Note:- Details i am fetching from ListView Activity to singleItem Activity) now i need to show Item Title and Cost for all the selected items into another activity ie- ViewCart (from singleItem Activity to ViewCart Activity)by using Add to Cart button on singleItem activity to send all selected records into ViewCart activity like:- Shopping Cart functionality Add to Cart then view selected records in a whole into another activity ViewCart, and i just want to show selected item's Title and Cost to another activity, still i am showing only the one selected item not all the selected item(s) by user in a session, and i am also not saving that record for complete session, but now i want to show all selected items by user into viewcart activity based on complete session. below i am placing singleItem and ViewCart Code:-
SingleItem Code:-
public class SingleMenuItem extends Activity{
static final String KEY_TITLE = "title";
static final String KEY_COST = "cost";
static final String KEY_THUMB_URL = "imageUri";
private EditText edit_qty_code;
private TextView txt_total;
private TextView text_cost_code;
private double itemamount = 0;
private double itemquantity = 0;
@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);
TextView txtheader = (TextView) findViewById(R.id.actionbar);
txttitle.setText(title);
txtheader.setText(title);
txtcost.setText(cost);
imageLoader.DisplayImage(thumb_url, imgv);
text_cost_code = (TextView)findViewById(R.id.single_cost);
edit_qty_code = (EditText)findViewById(R.id.single_qty);
txt_total=(TextView)findViewById(R.id.single_total);
itemamount=Double.parseDouble(text_cost_code.getText().toString());
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
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
itemquantity=Double.parseDouble(edit_qty_code.getText().toString());
itemamount=Double.parseDouble(text_cost_code.getText().toString());
txt_total.setText(Double.toString(itemquantity*itemamount));
}
});
ImageButton addToCartButton = (ImageButton) findViewById(R.id.img_add);
addToCartButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent in = new Intent
(SingleMenuItem.this, com.erachnida.restaurant.versionoct.FinalOrder.class);
in.putExtra(KEY_TITLE, getIntent().getStringExtra(KEY_TITLE));
in.putExtra(KEY_COST, getIntent().getStringExtra(KEY_COST));
startActivity(in);
// Close the activity
// finish();
}
});
}}
ViewCart Code:-
public class FinalOrder extends Activity
{
static final String KEY_TITLE = "title";
static final String KEY_COST = "cost";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
Intent in = getIntent();
String title1 = in.getStringExtra(KEY_TITLE);
String cost1 = in.getStringExtra(KEY_COST);
TextView txttitle1 = (TextView) findViewById(R.id.item_name);
TextView txtcost1 = (TextView) findViewById(R.id.item_cost);
txttitle1.setText(title1);
txtcost1.setText(cost1);
}
}
Remove your onclick code with below code.
public void onClick(View v) {
Intent in = new Intent
(SingleMenuItem.this, com.erachnida.restaurant.versionoct.FinalOrder.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_COST, cost);
startActivity(in);
// Close the activity
// finish();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.