0

I am using custom Radiobutton using listView, i want checked first radiobutton as default but not able to do it. when i am implementing the same for last radiobutton it is possible to checked as default.

WHAT I WANT: when i clicked second radiobutton first radiobutton(Default checked button) should be deselected.

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {

       @SuppressLint(“ViewHolder”) View returnedView =inflater.inflate(listItemViewId, null);
        final TextView itemName = (TextView) returnedView.findViewById(R.id.ic_colorname);
        itemName.setText(colorArrayList.get(position));
        final RadioButton radioButton= (RadioButton) returnedView.findViewById(R.id.ic_radioButton);

       //by default last radio button selected
        if (position == getCount()-1) {
            if (selected == null) {
                radioButton.setChecked(true);
                selected =radioButton;
            }
        }

       radioButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(“Id”, String.valueOf(radioButton.getId()));
                colorResult=colorArrayList.get(position);
                Log.d(“Button”,colorResult);

               if (selected != null ) {
                    selected.setChecked(false);
                }

               radioButton.setChecked(true);
                selected = radioButton;

               //for passing value to activity
                Intent intent=new Intent(“passingColor”);
                intent.putExtra(“color”,colorResult);
                LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);

           }
        });

       return returnedView;
    }
TheMatrix
  • 91
  • 9

0 Answers0