How to set radio button to checked when i click on list item

Camo

I am having a problem with my listview ( 2 textview and 1 radio button).

The problem: My idea is that the user clicks on the item in the listview and the radio button gets checked automatically.

I have been searching for a while, but I can't get the radio button to work.

My XML

   <RadioButton
        android:id="@+id/rdBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false" />

My Adapter

    r = (RadioButton) convertView.findViewById(R.id.rdBtn);
        r.setChecked(selectedPosition == position);
        r.setTag(position);
        r.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //r.setChecked(true);
                Toast.makeText(context, InformationActivity.result,
                        Toast.LENGTH_SHORT).show();
                selectedPosition = (Integer) view.getTag();
                notifyDataSetInvalidated();

            }
        });
        return convertView;

I tried

r.setChecked(true);

inside my activity class and the first click worked, but the second chooses a different item on the listview.

I hope some of you can help me. Thanks

Camo

I found the solution here: How to check checkbox on clicking an image?

        searchList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view,
                int position, long arg3) {

            LinearLayout item_view = (LinearLayout) view;
            final RadioButton itemcheck = (RadioButton) item_view
                    .findViewById(R.id.rdBtn);

            if (itemcheck.isChecked()) {
                itemcheck.setChecked(true);
            } else {
                itemcheck.setChecked(false);
            }

            itemcheck.setChecked(true);


<RadioButton
        android:id="@+id/rdBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false" />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to set radio button to checked when i click on list item

From Dev

Jquery how to get checked radio button when clicked an list item?

From Dev

How to set checked="checked" in first radio button?

From Dev

How to set a certain radio button to checked "true"

From Dev

How to set radio button checked initially in AngularJs?

From Dev

How to set a certain radio button to checked "true"

From Dev

how to set checked radio button by checking another radio button

From Dev

How to get checked radio button in list view?

From Dev

How can I get the text of radio button if radio button checked?

From Dev

jQuery: Add class if list item has checked radio button inside

From Dev

When click a link, Need to add checked attribute in radio button

From Dev

angular radio button set checked

From Dev

How to prevent second click on radio button if it was already checked in Android?

From Dev

Setting radio button checked true on button click

From Dev

set text in textview of a list item on click of button

From Dev

How do I disable text areas based on what radio button is checked when the page loads?

From Dev

I want a alert dialog to come up when a radio button is checked

From Dev

How to set scroll position to the level of checked radio button?

From Dev

How to set radio button as checked in dart polymer component

From Dev

how to set radio button checked in edit mode in MVC razor view

From Dev

How to always set default checked radio button programmatically android?

From Dev

How to set a radio button checked dynamically via php?

From Dev

How to set radio button as checked in dart polymer component

From Dev

How to always set default checked radio button programmatically android?

From Dev

How to checked jquery mobile radio button set via code

From Dev

How to set radio button checked default in other activities?

From Dev

How to set checked radio button using name and attr in jquery?

From Dev

How to get the text from radio button in a radio group when radio button checked state is changed

From Dev

On click how can I set checkbox to checked?

Related Related

  1. 1

    How to set radio button to checked when i click on list item

  2. 2

    Jquery how to get checked radio button when clicked an list item?

  3. 3

    How to set checked="checked" in first radio button?

  4. 4

    How to set a certain radio button to checked "true"

  5. 5

    How to set radio button checked initially in AngularJs?

  6. 6

    How to set a certain radio button to checked "true"

  7. 7

    how to set checked radio button by checking another radio button

  8. 8

    How to get checked radio button in list view?

  9. 9

    How can I get the text of radio button if radio button checked?

  10. 10

    jQuery: Add class if list item has checked radio button inside

  11. 11

    When click a link, Need to add checked attribute in radio button

  12. 12

    angular radio button set checked

  13. 13

    How to prevent second click on radio button if it was already checked in Android?

  14. 14

    Setting radio button checked true on button click

  15. 15

    set text in textview of a list item on click of button

  16. 16

    How do I disable text areas based on what radio button is checked when the page loads?

  17. 17

    I want a alert dialog to come up when a radio button is checked

  18. 18

    How to set scroll position to the level of checked radio button?

  19. 19

    How to set radio button as checked in dart polymer component

  20. 20

    how to set radio button checked in edit mode in MVC razor view

  21. 21

    How to always set default checked radio button programmatically android?

  22. 22

    How to set a radio button checked dynamically via php?

  23. 23

    How to set radio button as checked in dart polymer component

  24. 24

    How to always set default checked radio button programmatically android?

  25. 25

    How to checked jquery mobile radio button set via code

  26. 26

    How to set radio button checked default in other activities?

  27. 27

    How to set checked radio button using name and attr in jquery?

  28. 28

    How to get the text from radio button in a radio group when radio button checked state is changed

  29. 29

    On click how can I set checkbox to checked?

HotTag

Archive