How to get List item data in bindView when clicking on RadioButton in android?
Asked Answered
D

0

0

I have a ListItem having a person name e.g. ABCD and a RadioGroup having two RadioButtons. In my bindView() when i click any of RadioButton, it should update the data whose name is ABCD. But its only updating the lastItem shown in my ListView. Here is my BindView() :

@Override
        public void bindView(View view, Context context, Cursor cursor) {

            holder =  new  Holder();
            holder.stName = (TextView)view.findViewById(R.id.stName);
            holder.stName.setText(cursor.getString(cursor.getColumnIndex(AttendanceContentProvider.STUDENT_NAME)));

            _id_ = cursor.getString(cursor.getColumnIndex(AttendanceContentProvider._ID));
            _name_ = cursor.getString(cursor.getColumnIndex(AttendanceContentProvider.STUDENT_NAME));


            radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
            radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
            {
                public void onCheckedChanged(RadioGroup group, int checkedId) {

                 ContentValues values = new ContentValues();
                    switch (checkedId) {
                    case PRESENT:
                        values.put(AttendanceContentProvider.PRESENT, checkedId);
                        break;
                    case ABSENT:
                        values.put(AttendanceContentProvider.ABSENT, checkedId);
                        break;
                    case LEAVE:
                        values.put(AttendanceContentProvider.LEAVE, checkedId);
                        break;

                    default:
                        break;
                    }

                   String where = "((" + 
                            AttendanceContentProvider._ID + " LIKE '"+_id_+"') AND (" +
                            AttendanceContentProvider.STUDENT_NAME + " LIKE '"+_name_+"') AND (" +
                            AttendanceContentProvider._ID + " NOTNULL ))";
                    getActivity().getContentResolver().update(AttendanceContentProvider.STUDENTS_URI, values, where, null);


                }
            });

        }
Dermatophyte answered 8/8, 2014 at 5:57 Comment(4)
And while binding the view, it definitely gives different data for different ListItem. Its just the problem for RadioButton.Dermatophyte
You are creating a new view holder in bindView()? That seems really weird, what is the point of implementing the view holder pattern if you don't use it? And I guess something related to this is the source of your error. Show us more of your code.Kennie
I have solved this issue by making the cursor final and getting the position of cursor final too.Dermatophyte
Thnx for your response. Always glad to have your response.Dermatophyte

© 2022 - 2024 — McMap. All rights reserved.