I have done something that gives me result on click of button ..but i want the dynamic check box
Adpter class:
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 of 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));
}
});
Aucun commentaire:
Enregistrer un commentaire