[英]Arraylist only retrieves the last value
嗨,我正在使用Parcelable将一个数组列表从一个活动传递到另一个活动。
现在的问题是,当我单击BILL时,所有行都填充有arraylist的最后一个值。所以我想我无法在调用活动中获取整个arraylist。
这是相关的代码。
SpinPizza.java
public class SpinPizza extends Activity{
store temp= new store();
int i=0;
ArrayList<store> B = new ArrayList<store>();
//oncreate method
int n=Integer.parseInt(edittext.getText().toString());
temp.setOrder(s.getSelectedItem().toString(), s1.getSelectedItem().toString(),n);
B.add(temp);
TextView objText=(TextView) findViewById(R.id.pl);
TextView objText1=(TextView) findViewById(R.id.pl2);
objText.setText(B.get(i).getPizzaName());
objText1.setText(temp.getPizzaSize());
i++;
});
Button next1 = (Button) findViewById(R.id.bill);
next1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Bill.class);
myIntent.putParcelableArrayListExtra("myclass",B);
startActivityForResult(myIntent, 0);
}
});
}
比尔
public class Bill extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.calc);
ArrayList<store> B1 = new ArrayList<store>();
store temp1=new store();
Bundle bj=getIntent().getExtras();
B1=bj.getParcelableArrayList("myclass");
TableLayout tl = (TableLayout)findViewById(R.id.myTable);
for(int i=0;i<B1.size();i++)
{
TableRow tr = new TableRow(this);
tr.setId(100+i);
temp1=B1.get(i);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView b = new TextView(this);
b.setText(temp1.getPizzaName());
b.setId(200+i);
TextView b1 = new TextView(this);
b1.setText(temp1.getPizzaSize());
b1.setId(300+i);
TextView b2 = new TextView(this);
b2.setText(String.valueOf(temp1.getQuantity()));
b2.setId(400+i);
b.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(b);
b1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(b1);
b2.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tr.addView(b2);
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}}
}
请帮忙。
我看不到temp
的创建,也看不到在您的temp
修饰符行中使用的迭代temp.setOrder(s.getSelectedItem().toString(), s1.getSelectedItem().toString(),n);
。 似乎您不使用i
,这就是为什么您拥有相等的记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.