Skip to content

Commit

Permalink
Merge pull request #467 from OpenSRP/issue1733-radio-button-check
Browse files Browse the repository at this point in the history
Fixed NPE on radio button selection
  • Loading branch information
qaziabubakar-vd authored Apr 5, 2021
2 parents 63c3999 + 3bcedf5 commit b0df8e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion opensrp-chw-anc/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POM_SETTING_NAME=OpenSRP Client Chw Anc
POM_SETTING_ARTIFACT_ID=opensrp-client-chw-anc
POM_SETTING_PACKAGING=aar
VERSION_NAME=2.0.4-SNAPSHOT
VERSION_NAME=2.0.5-SNAPSHOT
VERSION_CODE=1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.DrawableRes;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -14,6 +13,8 @@
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.DrawableRes;

import com.vijay.jsonwizard.constants.JsonFormConstants;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -236,9 +237,10 @@ private void prepareRadioView() {
radioButtonChecked = rb;
}
rb.setTag(R.id.home_visit_radio_key, key);

rb.setOnClickListener(v -> {
if (rb.isChecked() && !radioButtonChecked.equals(rb)) {
radioButtonChecked.setChecked(false);
if (rb.isChecked() && !isSameRadioButton(rb)) {
if (radioButtonChecked != null) radioButtonChecked.setChecked(false);
rb.setChecked(true);
onSelectOption(key);
radioButtonChecked = rb;
Expand All @@ -251,6 +253,14 @@ private void prepareRadioView() {
}
}

public boolean isSameRadioButton(RadioButton radioButton) {
if (radioButtonChecked != null) {
return radioButtonChecked.equals(radioButton);
} else {
return false;
}
}

public String getTitle() {
return title;
}
Expand Down Expand Up @@ -340,7 +350,7 @@ private void initializeInfoIcon() {
}

protected void onShowInfo() {
if(getView() == null)
if (getView() == null)
return;

AlertDialog.Builder builderSingle = new AlertDialog.Builder(getView().getContext(), com.vijay.jsonwizard.R.style.AppThemeAlertDialog);
Expand Down Expand Up @@ -523,7 +533,7 @@ protected void onCancel() {
}

@Override
public void onClose(){
public void onClose() {
try {
if (getActivity() != null && getActivity().getSupportFragmentManager() != null)
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
Expand Down

0 comments on commit b0df8e3

Please sign in to comment.