我正在使用JSON將數據提取到listview中,我正在爲用戶單擊任何項目listview行提供工具,並且能夠查看選定的項目到另一個活動,仍然我只顯示用戶添加到cartcart活動中的單個項目,現在我想要顯示所有選擇的項目(s)在viewcart活動,如:在shoppingcart的viewcart活動形式,在這裏我只是顯示標題和成本,對此我用的ListViewItem行讀取到singleitemactivity點擊如何將所有選擇的項目顯示爲像購物車的視圖活動中的其他活動
SingleItem代碼: -
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();
}
});
}}
FinalOrder代碼: -
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);
}
}
,你在'填數據itemsList'它是空的。這就是它通過例外的原因。 –
你可以告訴我,在單項活動中,我使用itemlistview點擊獲取數據,現在我只想顯示這些數據,如: - 只有標題和費用的viewcart活動,所以我需要使用itemslist或不? – Stanley
您想要將'SingleMenuItem'中收到的數據發送到'FinalOrder'活動?那麼就這樣做'in.putExtra(KEY_TITLE,getIntent()。getStringExtra(KEY_TITLE)); in.putExtra(KEY_COST,getIntent()。getStringExtra(KEY_COST));' –