2011-04-01 52 views
0

您好我想過去從一個活動到另一個使用Parcelable一個ArrayList ..的ArrayList只檢索的最後一個值

現在的問題是,當我點擊BILL,所有行被填充的最後一個值arraylist..So我想我不能夠中檢索在調用活動的整個數組列表...

下面是相關代碼..

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); 

      } 

     }); 

} 

Bill.java

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)); 


}} 

}

請幫助。

回答

1

我看不到temp的創建,我也看不到在temp修改器行temp.setOrder(s.getSelectedItem().toString(), s1.getSelectedItem().toString(),n);中使用的迭代。看起來你不使用i這就是爲什麼你有相同的記錄。

+0

@ user639183我這樣做... temp在第二行創建..(請參閱代碼)...其實我發佈整個代碼...我的壞...這是迭代.. 。 – 2011-04-01 17:09:17

+0

公共布爾安其(視圖v,INT的keyCode,KeyEvent的事件){ \t如果((event.getAction()== KeyEvent.ACTION_DOWN)&&(的keyCode == KeyEvent.KEYCODE_ENTER ||的keyCode == KeyEvent.KEYCODE_DPAD_CENTER) ){int n = Integer.parseInt(edittext.getText()。toString()); (s.getSelectedItem()。toString(),s1.getSelectedItem()。toString(),n); B.add(temp); \t \t //文本視圖顯示 \t \t i ++; – 2011-04-01 17:14:11

相關問題