In my application I am using Custom Listview with row as TextView and CheckBox.
Now I want that when I check CheckBox at that time that respective row have to Disable(unfocasable).
What should be the code inside CheckBox OnCheckedChangeListener
I also tried to disable rowlayout inside Listener but not got success...
following is code I am using inside getView method of Adapter
final RelativeLayout RL=(RelativeLayout)convertView.findViewById(R.id.VTRLmain);
check.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
{
if (isChecked)
{
RL.setEnabled(false);
templist.add(getItem(position));//using for another activity
}
}
});
give in xml code for checkbox
android:focusable="false"
it won't hide listview textboxs.
and check the application theme.
In the adapter there is a method named isEnabled which you can overide. Try to do in your custom adapter
Try this code:
#Override
public boolean isEnabled(int position) {
if(checkbox1.isChecked()){
return false;
}
return true;
}
Related
I want to use some methods on this switch which is within a RecyclerView. I want to use methods like mSwitch.setEnabled(true) in the MainActivity:
how do I do this? Please help! I'm new to android and the sad part, I haven't subscribed any android course
you click on child views like this in recyclerView from recyclerViewAdapter
viewHolder.switchView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// do something, the isChecked will be
// true if the switch is in the On position
}
});
I have a custom list view and each item of it has a check box and a text field. I want to disable the check box in every other row of the list view if the check box of the first row is enabled.
Since you are stating that if the first check box is clicked all the others should be disabled, do a check in your onBindView() to see if the checkbox is checked. if it is, set a value to say that it is, and for all the following list view entries set the checkbox to disabled.
In your onCheckChangedListener():
checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked()){
firstCheckboxChecked = true;
}
});
Then in your onBindView for the rest:
if(firstCheckBoxChecked){
checkbox.setEnabled(false);
}
Here I am putting some rough solution which will help you.
classs model
{
boolean status;
model(boolean status){
this.status=status;
}
}
List<model> list_model= new ArrayList<>();
list_model.add(false);
list_model.add(false);
list_model.add(false);
list_model.add(false);
add this model with listview adapter.
//Adapter coding
checkbox.checked(check)
//write below code in checkbox.setOncheckedItemSelect method.
//you will get already checked parameter in that method.which will put into list
list_model.add(checked);
//here call listview notify datasetchangedListener.
create a boolean variable isFirstEnbled in your adapter. then on click first item's checkbox set this value as isFirstEnbled=true .
adapter.notifyDataSetChanged()
This recreate the view with isFirstEnabled set as true
Here's my aproach:
I have a custom ListView containing a custom Adapter containing two different kind of Views. One of them has a CheckBox in each View.
I just want to notify the Activity when one of those CheckBoxes have been clicked, and to pass it a boolean: true if ANY of the boxes are checked, false otherwise.
How should I do it?
I just need the theorethical answer, not code.
Thank you very much.
1- implement the activity by checkedChangeListene and override the code in activity
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if ( isChecked )
{
Object obj = buttonView.getTag();
// perform logic
}
}
2- pass the activity in custom adapter constructor.
3- set in getView
CheckBox chkBx = (CheckBox ) findViewById( R.id.repeat_checkbox );
if(null!=chkBx ){
chkBx.setOnCheckedChangeListener(mActivty);
chkBx.setTag(position);
}
In my Android application I have a custom ArrayAdapter for managing rows in a List that implements onCLickListener.
In the onClick() method I want to show the context menu.
public class MyAdapter extends ArrayAdapter<MyClass> implements
OnClickListener {
public void onClick(View v) {
v.showContextMenu();
}
}
In my main List Activity class I override the onLongListItemClick() method that starts a different Activity.
When I click on a row in the list - the context menu is shown correctly but a second later the onLongListItemClick() is also executed. How to stop this happening?
thanks!
After your comments, I think I have a solution. Don't use the row onClick for the context menu, set a click listener in your adapter for the checkbox and show your context menu from there. That way you avoid the onLongListItemClick.
To make both the checkbox and the row clickable, add this to the checkbox definition in your XML:
android:focusable="false"
android:focusableInTouchMode="false"
EDIT
This should do the trick:
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked){
View v = buttonView.getParent(); // get the parent row view containing the checkbox
v.showContextMenu(); // show the context menu
}
}
}
I've created an adapter for ViewPager. When I create it, I also have to dynamically create radio buttons on the layouts. However, by clicking one of the radio buttons, i need to notifyDataSetChanged of the adapter it's inside. How do I access that adapter? For example, if I wanted to do this:
radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
viewPagerLength++;
// need to call notifyDataSetChanged();
}
}});
This can be done by setting radioButton like so:
final RadioButton radioButton = (RadioButton) findViewById(R.id.rb);
and then you can access radioButton from within.