0
as u all can see ,if i check to my checkbox the price should appear below,beside the makepayment button if i check more than one check box addition should be perform and same way the subtraction我想補充的recyclerview複選框的值
我做了什麼,讓我產生按鈕的點擊..但我想的動態複選框
Adpter類:
holder.payment.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Buy_Data contact = (Buy_Data) cb.getTag();
contact.setSelected(cb.isChecked());
carsList.get(position).setSelected(cb.isChecked());
Toast.makeText(v.getContext(),"Clicked on Checkbox: " + cb.getText() + " is "
+ cb.isChecked(), Toast.LENGTH_SHORT).show();
}
});
Mainclass recyclerview的:
makepayment=(Button)findViewById(R.id.makepayment);
makepayment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ArrayList<Buy_Data> stList = ((Mts_Payment_Adapter)adapter).getStudentist();
int a=0;
for (int i = 0; i < stList.size(); i++)
{
Buy_Data singleStudent = stList.get(i);
if (singleStudent.isSelected() == true)
{
a = a + Integer.parseInt(singleStudent.getPrice());
}
else
{}
}
Toast.makeText(Mts_Payment.this, "Selected Students:" + a,
Toast.LENGTH_SHORT).show();
total=(TextView)findViewById(R.id.aaa);
total.setText(String.valueOf(a));
}
});
其回調shud在適配器類中實現 –
回調接口 –