Getting radio button value from custom list in android

拟墨画扇 提交于 2019-12-02 04:36:33

I want to reach id of selected radio button from this code.

You have to play with setTag & get getTag property to fetch actual id of your selected radio button,

holder.button.setTag(position);  

holder.button.setOnClickListener(new View.OnClickListener() {  
                public void onClick(View v) {   
                 int pos = (Integer) v.getTag();
                 Log.i("ID of radiobutton","Order Edit @ position : " + pos); 
                 String _Str1=array1.get(pos);
                 String _Str2=array2.get(pos);
                 }       
                });  

This way you will get the exact values of textview from your rows.

Assuming that you need to access the TextView in the onClick method,

@Override
public void onClick(View v) {
    if((position != mSelectedPosition && mSelectedRB != null)){
        mSelectedRB.setChecked(false);
    }
    mSelectedPosition = position;
    mSelectedRB = (RadioButton)v;
    View containerView = (View)v.getParent();
    TextView textView1 = (TextView)containerView.findViewById(R.id.TextView01);
}

EDIT:

I see that you have declared the holder object as final. In that case, you can directly access the holder.text1 and holder.text2 objects from within the event listener.

Code like this in your button onClick

 int selected_radioISAwayGroup = holder.radioISAwayGroup.getCheckedRadioButtonId();
                holder.radioISAwayButton = (RadioButton) findViewById(selected_radioISAwayGroup);

                System.out.println("holder.radioISAwayButton:"+holder.radioISAwayButton.getText().toString());
                if(holder.radioISAwayButton.getText().toString().equalsIgnoreCase("Pre"))
                {
                    //Count +1 for presents
                }
                else if(holder.radioISAwayButton.getText().toString().equalsIgnoreCase("Abs"))
                {
                    //Count +1 for Absents
                }
                else
                {
                    //Count +1 for Half
                }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!