当用户单击添加到购物车时,我有一个产品目录屏幕,它将被添加,下一个屏幕显示,其中产品描述和价格将通过删除按钮给出。我想为每个产品添加复选框,并且只有该产品将是删除将在复选框中选中,当用户单击删除按钮时,产品将被删除。我尝试添加复选框,请帮助我如何做到这一点?代码在其下方,包含删除按钮,并且在删除按钮上执行操作。但不是复选框,我怎么能这样做。非常感谢任何帮助。
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();
}}