2012-12-06 82 views
-1

每個產品我有當添加到購物車將被添加和下一下一屏顯示的用戶點擊其中的產品說明及價格將刪除button.i給予希望產品目錄屏幕添加複選框與每個產品,只有該產品將被刪除,將在複選框中檢查,當用戶點擊刪除按鈕,產品將被刪除。我試圖添加複選框,請幫我我怎麼能這樣做? 代碼是它下面contian刪除按鈕和動作上刪除執行button.But不復選框我怎麼能這樣做this.Any幫助表示高度讚賞。如何添加複選框,在Android的

public class CheckOutClass extends Activity implements OnClickListener{ 
public static int finalPrice = 0; 
int unitPrice=0 ; 
int quantity =0 ; 
int[] totalPrice = null; 
ImageView[] btnRemove = null; 
LinearLayout ll = null; 
ScrollView sv =null; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    sv = new ScrollView(this); 
    ll = new LinearLayout(this); 
    ll.setOrientation(LinearLayout.VERTICAL); 
    sv.addView(ll); 
    LoadUi(); 
} 

public void LoadUi(){ 

    int lengthOfRecords = helper.vctrcategoryIds.size(); 
    btnRemove = new ImageView[lengthOfRecords]; 

    for(int i = 0; i < helper.vctrcategoryIds.size(); i++) { 
      getPackageName()); 

    ImageView imgView = new ImageView(this); 
    imgView.setImageBitmap(helper.vctrImages.elementAt(i)); 
    ll.addView(imgView); 

    TextView txtDescription= new TextView(this); 
    txtDescription.setText(helper.vctrdescription.elementAt(i).toString()); 
    ll.addView(txtDescription); 

    TextView txtPrice= new TextView(this); 
    txtPrice.setText("Unit Price: " + helper.vctrprice.elementAt(i)); 
    ll.addView(txtPrice); 

    TextView txtQuantity= new TextView(this); 
    txtQuantity.setText("Quantity: "+ helper.vctrQuantity.elementAt(i)); 
    ll.addView(txtQuantity); 

    //remove button 

btnRemove[i]= new ImageView(this); 
btnRemove[i].setImageResource(R.drawable.remove); 
btnRemove[i].setMaxHeight(40); 
btnRemove[i].setMaxWidth(35); 
btnRemove[i].setAdjustViewBounds(true); 
btnRemove[i].setId(i); 
btnRemove[i].setOnClickListener(this); 
ll.addView(btnRemove[i]); 

} 

    totalPrice = new int[helper.vctrprice.size()]; 

    for(int i=0;i<helper.vctrprice.size();i++){ 

      String strPrice1 = helper.vctrprice.elementAt(i).toString(); 
      unitPrice = Integer.parseInt(strPrice1); 
      String strQuantity1 = helper.vctrQuantity.get(i).toString(); 
      quantity = Integer.parseInt(strQuantity1); 

      totalPrice[i] = unitPrice*quantity; 

      System.out.println("Total price: per product: " + totalPrice[i]); 
      } 
       int finalPrice = 0; 
       for(int i=0;i<totalPrice.length;i++){ 

         finalPrice = finalPrice + totalPrice[i]; 


       } 

      System.out.println("final Price: " + finalPrice); 
      helper.finalprice = finalPrice; 

      String str = Integer.toString(finalPrice); 
      TextView txtfinalprice= new TextView(this); 
      txtfinalprice.setText("Total Price: " + str); 



      ll.addView(txtfinalprice); 

      ImageView btnAddMore = new ImageView(this); 
      btnAddMore.setImageResource(R.drawable.moreprod); 
      btnAddMore.setMaxHeight(40); 
      btnAddMore.setMaxWidth(35); 
      btnAddMore.setAdjustViewBounds(true); 
      ll.addView(btnAddMore); 

      btnAddMore .setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      Intent i = new Intent("com.test.spinnerdem",null); 
      startActivity(i); 
     } 
    }); 

    ImageView procedCheckout = new ImageView(this); 
    procedCheckout.setImageResource(R.drawable.proceed); 
    procedCheckout.setMaxHeight(40); 
    procedCheckout.setMaxWidth(35); 
    procedCheckout.setAdjustViewBounds(true); 

     ll.addView(procedCheckout); 

    procedCheckout.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      if(helper.userLoggedIn == null){ 
      Intent i = new Intent("com.test.androidlogin",null); 
      startActivity(i); 
      } 
      else { 

        Toast.makeText(CheckOutClass.this, "User Logged In", Toast.LENGTH_LONG).show(); 
        Intent i = new Intent("com.test.billing", null); 
        startActivity(i); 

      } 
     } 
    }); 

    this.setContentView(sv); 

} 


public void onClick(View v) { 
    // TODO Auto-generated method stub 
    ll.removeAllViews(); 
    int Id = v.getId(); 
    System.out.println("Button Clicked"+ v.getId()); 
    helper.vctrIds.removeElementAt(Id); 
    helper.vctrshopIds.removeElementAt(Id); 
    helper.vctrcategoryIds .removeElementAt(Id); 
    helper.vctrproducts.removeElementAt(Id); 
    helper.vctrprice.removeElementAt(Id); 
    helper.vctrdescription.removeElementAt(Id); 
    helper.vctrImages.removeElementAt(Id); 
    helper.vctrQuantity.removeElementAt(Id); 

    LoadUi(); 

     }} 
+0

採取自定義列表視圖的幫助。 –

回答

0

看代碼here

您可以選擇列表視圖中的多個項目。檢查here