Android setChecked animation - android

I have a problem on checkbox animation when setChecked(true).
Let me explain my condition.
I have a gridview inside viewpager and one checkbox above the viewpager.
I set an adapter to gridview. There are a checkbox and a icon in the adapter.
When click an item, checkbox animation works fine. However, when try to select all items by one checkbox above the viewpager, all items are selected without checkbox animation, just can see only 2 views, checked box and unchecked box.
Please help me out. Thanks.

// ViewHolder
CheckBox mCb;
mCb.post(new Runnable(){
#Override
public void run(){
mCb.setChecked(Model.isChecked());
}
});
Um... The problem with this code is a bit slow

Related

custom listview save selected item position

I create a custom listview.
I want to select any item using another button click or something views click.
Already I tried via these code for custom selection.
And I also want to get previous selected item on resume.
listView.setItemChecked(2,true);
listView.setSelection(2);
listView.requestFocus();
But everytime , I failed.
I used this method to create custom listview.
Android ListView with Custom Adapter Example Tutorial
Advance Thanks .
For setItemChecked to work, your list items need to be Checkable; you can, for example use CheckedTextView (at the top level of the item view, no further layout around it).
For setSelection to work, you need to use it inside a Runnable, like so:
listView.post(new Runnable() {
#Override
public void run() {
listView.setSelection(2);
}
});
In both cases, don't ask why.
For a selection to become visible, you can put a statelist in the background attribute of your list item.

Android: Identify listviewItem when checkbox of item is checked/unchecked

I got a listView with dynamically created items. Each item has a checkbox which can be checked/unchecked. When the checkbox is pressed this function is called:
public void updateClientList(View v) {
}
Now I want to change the specific item in my arraylist which is the base of the listview. But how do I know which checkbox was checked?
How can I do that? Thanks for your help!
If you only have a checkbox, you can use the OnItemClick listener that gives you position besides the view, but with this solution you have to update the checkbox manually so it doesnt consume the item click.
Another way is to use setTag(position) on the views you supply when binding.
You should consider moving on to RecyclerView.
https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

Android: Dynamically show all checkboxes in adapter onLongClick

I was learning custom adapter concepts recently.
Problem is during onlongClick in a row,
I want to show checkboxes checked in the longclicked row, which is in android:visibility="gone" initially. And also to show checkboxes in other rows which are not clicked in unchecked state.
I changed some parts of this code here.
http://windrealm.org/tutorials/android/listview-with-checkboxes.php
In simplerow.xml I made
android:visibility="gone" initially.
Now I made a onLongClickListener inside getView(...) method
textView.setOnLongClickListener (new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
CheckBox cb = (CheckBox) v;
Planet planet = (Planet) cb.getTag();
planet.setVisibility(View.VISIBLE);
planet.setChecked(true);
}
});
Now the above code will affect only the longClicked row. How do I make changes in the non-clicked rows?
Calling notifyDataSetChanged() on long click did not work because the other rows have checkbox initially in android:visibility="gone".
Please help. Is any other work around possible?
ListView accompanies Adapter. All your model items would be inflated into the view items through the implemented method named getView from Adapter. If you want to update view without changing data, call notifyDataSetChanged afterwards.

Listview onItemClick() checkable

Im having a listview with items in a custom relativelayout which implements Checkable. It contains a checkbox which gets checked/uncheked via the checkable interface.
setFocusable is set to false for the Checkbox, so that I can use onItemClicked for the listview.
Now when an item is clicked the checkbox is also selected. I am getting crazy about this.
In the getView Method for my Adapter I assign an onCheckChangeListener to the checkbox.
This listener is called everytime a listitem is clicked and checks the Checkbox.
I saw questions how to select a checkable listitem onitemclick, and im getting this behaviour by default....
The Problem with this behaviour is:
The checkbox should get checked by clicking the checkbox not clicking the listitem. I start an Actionmode for the current visible Fragment when a checkbox is clicked, and i replace the current fragment when a listitem is clicked. BOTH is happening right now and that means, wrong Actionmode for wrong fragment and force close on backpress...
best regards vino
I think you have to make all other item in custom listview to setFocusable="false"

Programatically unchecking items in a dialog on Android

I am displaying a list with checkboxes in a dialog. The list looks something like-
Item 1
Item 2
All
with a checkbox beside each item. Now the requirements is-
If Item 1 or Item 2 or both are already checked, and All is selected, Item 1 & 2 should be unchecked.
To accomplish this, I implemented DialogInterface.OnMultiChoiceClickListener 's onClick listener.
public void onClick(DialogInterface dialog, int which, boolean isChecked)
{
if(which == 2 && isChecked)
{
((AlertDialog)dialog).getListView().setItemChecked(0, false);
((AlertDialog)dialog).getListView().setItemChecked(1, false);
}
}
But this does not work. I even tried invalidating the listview by calling Invalidate() & InvalidateViews(), but no success.
Any help will be really appreciated.
Thanks,
Akshay
If I understand correctly, the checkboxes are in a list. There's been a question with the opposite situation: trying to uncheck all boxes. The solution seems to be to call
adapter.notifyDataSetChanged()
Here is the link to that question: Uncheck all checkboxes in a custom ListView
EDIT: Okay, I'll try again :-) Found another question about it: android: Refresh ListView using ListAdapter and SimpleCursorAdapter Hope this helps! :-)

Categories

Resources