the problem is I can't remove " , " while there is only 1 item checked and when there are more than one I don't know how to remove the " , " from the end.
public class CheckBox extends AppCompatActivity implements View.OnClickListener {
ImageButton check_button;
CheckBox eminem , dre , tupac , royce , logic , big_sean;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_e10_check_box);
setTitle("Check Box");
Inits();
}
private void Inits(){
check_button = findViewById(R.id.check_button);
eminem = findViewById(R.id.eminem);
dre = findViewById(R.id.dre);
tupac = findViewById(R.id.tupac);
royce = findViewById(R.id.royca);
logic = findViewById(R.id.logic);
big_sean = findViewById(R.id.big_sean);
check_button.setOnClickListener(this);
}
@Override
public void onClick(View view) {
String result = "Your Favorite List : x";
String singers = "";
if(eminem.isChecked()){
singers += "Eminem" + " , " ;
}
if (dre.isChecked()){
singers += "Dr.Dre" + " , ";
}
if (tupac.isChecked()){
singers += "Tupac" + " , ";
}
if (royce.isChecked()){
singers += "Royce" + " , ";
}
if (logic.isChecked()){
singers += "Logic" + " , ";
}
if (big_sean.isChecked()){
singers += "Big Sean" + " , ";
}
app.t(result.replace("x" , singers));
}
}