I have a custom list and a switch in each line, it works correctly, but I want to reach the identifier of the selected switch from this code. For example, when I need the textview1 value of a selected row, how can I assemble it? Thank you in advance. Here is my code:
private static class Adapter extends BaseAdapter { private LayoutInflater mInflater; private int mResourceId = 0; private RadioButton mSelectedRB; private int mSelectedPosition = -1; public CitizenAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return array.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.table_row_citizen, null); holder = new ViewHolder(); holder.text1 = (TextView) convertView.findViewById(R.id.TextView01); holder.text2 = (TextView) convertView.findViewById(R.id.TextView02); holder.button = (RadioButton)convertView.findViewById(R.id.radioButtonCitizen); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.text1.setText(array1.get(position)); holder.text2.setText(array2.get(position)); holder.button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if((position != mSelectedPosition && mSelectedRB != null)){ mSelectedRB.setChecked(false); } mSelectedPosition = position; mSelectedRB = (RadioButton)v; } }); if(mSelectedPosition != position){ holder.button.setChecked(false); }else{ holder.button.setChecked(true); if(mSelectedRB != null && holder.button!= mSelectedRB){ mSelectedRB = holder.button; } } return convertView; } static class ViewHolder { TextView text1; TextView text2; RadioButton button; } }
source share