Doubts in Using CustomListView - android

I just created a ListView, the itemclickevent works fine with it. But when i add a combox box to the list view, the focus goes within the selected object list in the object only, but cannot get the click event, but i can check or uncheck the checkBox.
Any Ideas how to use this? I want the click event for selected object as well as the check box.

I'm not sure I understand your question correctly. But if you want to get a itemClickedEvent for a listview Item at the moment the user checks a checkbox this is not easily possible.
The Checkbox will handle the press on it and because the event is handled the list won't get the information. You can try to set the clickable of the checkbox to false and check and uncheck the box yourself at the moment the user clicks the listitem.

Related

Change text of one specific context menu item

I've created a context menu for my recycler view items. In the menu I have Watch (like favourites), Share and Hide. Now what I want to do is get the specific position of the Recycler View and check if the Watch or Hide button has been pressed. How can I go about doing this? I've used a flag but that just checks the whole Recycler View so that doesn't work.
I can show source code on request too. I know it needs to go in my Adapter but can't figure out the position of it
Thanks in advance.
just add a boolean variable in your List to check whether to show Watch or Hide button.
use getAdapterPosition() method when user clicked the clicked on button and then use that position to update value in your model class.

Delete Button on Listview

In my android app, I have a listview with an option to delete items from it
on the same screen. The delete button lies at the bottom of the list view
and there's a function written for deleting items and refreshing the list view.
This function is being called in onClick() of the List View.
This is where the problem lies.
In delete button's onClick I have first made a check for knowing which item to delete -
if (ListView.INVALID_POSITION != mListView.getSelectedItemPosition()) {
//delete the selected item
}else{
//do nothing
}
So whenever user touches delete button the focus from list view is removed and we get invalid as the list view position and hence the item is not deleted.
I also tried to store the value of selected item in a constant and update it in list view's onItemSelected() method and then remove the condition from Delete Button's onClick
.This works but causes another problem - If the user taps into empty area then focus from list view is removed and it appears that nothing is selected, but if u press delete button and then it deletes the last selected item as it is coming from a constant.
This is the problem I am facing.
Please suggest what to do.
Selection is useful only in keyboard mode, its turned off in touch mode so, getSelectedItemPosition() is not always reliable.
Read do's and don't in this developer blog entry.
If you want to use a single button, Set ListView choice mode to Single/Mutliple, then, on button click, get the checked items and delete them, refresh ListView after that.
Try to implement the onitemclickListener() and get the item id and delete the item clicked in the arrayadapter by implementing the onclick() for the button and next call adapter.notifyDataSetChanged();

How to custom checkbox in listview to check only one like radio button

I have list which contain checkbox in each list and I want to define these checkbox for only one of check box can select (like radio button) anybody have any ideas?
Set clickable/focusable/focusableInTouchMode to false, and then the list item vill receive the click, then set the checkbox state manually.
If the checkbox is clickable, then the item will not receive any event, this is an old Android bug still not fixed. Even worse if you want to use EditTexts, but don't get me there

android select multiple items in ListView?

I have a ListView and I want to select multiple items in the ListView without using CheckedTextView.
Please help !!
You don't really need a CheckBox. All you need is a boolean flag on your list objects. When the user clicks an item you change the state of the flag, and probably the background or text color for that list item.
I never tried it, but I would use ListView with checkbox but non visible.
Perform the setChecked(True) when the user press on an item.
I would also try changing the item background when the checkbox is checked.

Delete all list items which are checked

I have a ListActivity binding to a database with a Custom SimpleCursorAdapter.
in each of my list items I have 4 texts, image and checkbox (each one is set to focusable:false).
In the list itself I have a long button so when I press on it, I want it to delete all the
rows which thire checkboxes are 'checked'.
Now, I have tried many techniques in order to achieve a simple operation (click listeners, CheckedtextView as shown in the tutorial) but was not successful.
There is also another weird phenomenon occurring, after I #Override onListItemClick, also i dont get any calls at all while I am pressing on any of the list's rows.
Does anybody have any idea how to solve these issues? Thanks.
Thanks,
Moshic.
Are you calling super.onListItemClick(ListView, View, int, long);? if so, try write out a Log.d("ListView", "My list has been clicked"); and see if that comes out in the Logcat. If it doesn't, try extends ListActivity in your activity declaration. comment back if you want my help, I'll be ready to help as much as possible
create your own adapter with following features
-in getView() you have to set click listener for check box(it will be own listener for each check box)
-each element of adapter contains flag checked/unchecked, and you should set it by check box click listener from previous point
in activity with delete button click listener you have to get checked elements from adapter and do with them what you want
after then you should update list view for example by calling (your adapter).notifyDataSetChanged()

Categories

Resources