I have a product catalog screen when the user click on add to cart it will be add and next next screen display in which product description and price will be given with remove button.i want to add checkbox with each product and only that products will be removed that will be checked in checkbox and when user click on remove button that products will be removed.I tried to add the checkbox please help me how could i do this? The code is below it contian remove button and action is perform on remove button.But not checkbox how could i do this.Any help is highly appreciated.
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();
}}