Reputation:
I have done the radiogroup for this fragment using if else while unclickable. I tried testing it, but it remains the same. Can you please figure out what is the problem with this?
public class Competencies extends Fragment {
View rootView;
Button submit;
TextView title;
RadioGroup rg1, rg2, rg3, rg4;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.competencies, container, false);
RadioGroup();
submit = rootView.findViewById(R.id.btnSubmit);
submit.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FF00574B")));
submit.setTextColor(Color.parseColor("#FF000000"));
submit.setClickable(false);
title = rootView.findViewById(R.id.tvTitle);
Bundle bundle = getArguments();
if(bundle != null) {
title.setText(bundle.getString("title"));
}
Submit();
return rootView;
}
public void RadioGroup(){
rg1 = rootView.findViewById(R.id.rgFirstQuestion);
rg2 = rootView.findViewById(R.id.rgSecondQuestion);
rg3 = rootView.findViewById(R.id.rgThirdQuestion);
rg4 = rootView.findViewById(R.id.rgFourthQuestion);
}
public void Submit()
{
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(rg1.getCheckedRadioButtonId()==-1 && rg2.getCheckedRadioButtonId()==-1 && rg3.getCheckedRadioButtonId()==-1 && rg4.getCheckedRadioButtonId()==-1) {
}
else
{
submit.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FF4CC8B7")));
submit.setTextColor(Color.parseColor("#FFFFFFFF"));
submit.setClickable(true);
CompetenciesSuccessful successful = new CompetenciesSuccessful();
getFragmentManager().beginTransaction().add(R.id.fragment_container,successful).commit();
}
}
});
}
}
Upvotes: 0
Views: 51
Reputation: 3152
you can use this
public void Submit(){
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(rg1.isChecked() && rg2.isChecked() && rg3.isChecked() && rg4.isChecked()) {
submit.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FF4CC8B7")));
submit.setTextColor(Color.parseColor("#FFFFFFFF"));
submit.setClickable(true);
CompetenciesSuccessful successful = new CompetenciesSuccessful();
getFragmentManager().beginTransaction().add(R.id.fragment_container,successful).commit();
}
Upvotes: 1