I have a scenario that we should have a single choice mode radio button in listview. when I click on the radiobutton it should go to enable state. when I click on the whole item then it should redirect to the new activity.
You can simply create a composite view for this. Due to the way the native radiobutton is built you can't differentiate between click on the circle or click on the item.
You can have a radiobutton without text associated to a textview or whatever view you may need. Then you simply listen to clicks on the textview or the radiobutton.
For the radiobutton you can keep the default behavior and for the textview you have a button-like onClickListener.
Related
I'm building an ExpandableListView in which there are groups of radio buttons.
Currently, I am able to handle the click event on each radio button and select the corresponding one and deselect the others. But there is just one more thing needed to make it perfect. That is displaying the value of the selected checkbox in the group view so the user can see what is selected without expanding it.
For that purpose, I have a TextView in the group view. Is it possible to update that TextView when a checkbox is selected in the child view?
Here is a screenshot of what I have right now:
Basically what I want to accomplish is to make it write the value of the selected checkbox instead of "Regular".
Thanks.
in your example, it seems perfectly reasonable to save a reference to your TextView inside a member variable when it is created. you can then easily update its value by calling setText() on it from within your checkbox's click handler.
it is neither necessary nor desirable to call notifyDataSetChanged().
I started working with check boxes in android but got confused when to use setCheckedChangelistener and setOnclickListener, pleasae tell me when to select appropriate one and also difference in their implementation.
OnClickListener calls in case, when you click any View (Button, TextView, EditText and other). OnCheckedChangeListener call when View change checked state. It works with Views like (ToggleButton, CheckBox). This Views change and store state after click.
Good luck!
onClickListener is used for widgets like - Buttons , Textview , EditText , LinearLayout , FrameLayout , etc.
onCheckedChangeListener is used for compound button widgets like - CheckBox, RadioButton, Switch, ToggleButton .
I am working on an Android application where I want a user to select a RadioButton corresponding to one category, and add a spinner within the same layout, where the displayed spinner depends on the radio button that was selected. This means for each RadioButton I have a different spinner. I know how to add view to the layout but I was wondering how I might go about storing each of the individual spinners and requesting them when the corresponding category is selected. Is it possible to store them within a layout activity and select the correct one using findViewById?
Agree to Trushit
add all the spinners in the view & on performing the Radio Button event set the visibility of the spinners.
yourSpinner.setVisibility(View.VISIBLE);
&
yourSpinner.setVisibility(View.GONE);
I am developing an application for Android, and for that I am trying to make a ListView act in such a way, that when a user presses an empty entry, he can start typing text directly into that empty entry, and that when the user touches any other part of the screen, it is saved. Is there a way to do this? I was thinking of using onClick somehow, but I have no concrete approach.
Here is one basic, general approach:
For each row of the ListView, create a layout that has a visible TextView and a EditText with the visibility set to gone.
Use an onClickListener for each row to swap the visibilities of the TextView and EditText (respectively, gone and visible) when the row is selected.
Track the active row for clicks to another row or background.
When the active row changes, set the value of the EditText to the TextView and return them to their original visible states.
Other approach that could be taken is using the View.OnFocusChangeListener and the TextWatcher you can get more detail about them here http://developer.android.com/reference/packages.html
I've found a few examples of adding a RadioButton or a CheckBox to a ListView. I've even found one that uses one or the other depending on whether the ListView allows multiselect or not.
What I'm trying to do is have a RadioButton followed by a CheckBox. If the RadioButton is selected, all other RadioButtons should clear, and all CheckBoxes should clear. If a CheckBox is selected, all RadioButtons should clear, but I should be able to select more CheckBoxes on my own.
In other words, it's multiselect and singleselect just depending on the user's preference.
I created a class for the linearlayout with both views and a TextView. I am using the toggle, and setChecked methods. But I can't tell which view actually was pressed on, just that the LinearLayout was pressed.
public class CheckableLinearLayout extends LinearLayout implements Checkable
{}
Any ideas?
Make a Listener for your radiobuttons and in onClick() loop through all of your checkBoxes and call checkBox.setSelected(false). That will take care of clearing all checks when a radio button is chosen. Then make a seperate Listener for your check boxes and inside the onClick() of that find the radioButton that is selected and call radioBtn.setSelected(false)
Make sure your radio buttons are in a RadioGroup and that will handle making sure that only one of them can be selected for you without having to do anything extra.