Expanded and Collapse CardView not working fine - android

In RecyclerView, there is a problem about the adpter which assigns to every single item the ID. I use a button for every item (are CardView), and this button seems not to have a unique ID, because when I select it, it makes me expand the 1° and 13° item. I also need the expansion of the single cardview I check actually, I've notice that it expands the other cards through the list.
Why? How I can fix it?

Related

collapse recyclerview with different view types

So, I have a recyclerview with multiple view types. I'm using this link to generate my adapter class, becauseI have multiple viewholders in my recyclerview. Now the problem I have is with collapsing certain items inside it. What I want is whenever I press
the green toggle, item 2 and 3 in the list should collpase but 4,5,6 should remain upon,unless you have clicked on the green item ofcourse. I tried many ways to approach this but I can not achieve this with the link provided. Is there any way I can achieve this?
When you click collapsing button you have to remove your collapsing data from your all source list. When you remove your item from your list recyclerView automatically animates it.After that when you want to show it again you have to insert it your list again and notify that.RecyclerView also animates again when you insert it. There is a useful link here for inserting and removing special data from recyclerView https://medium.com/#suragch/updating-data-in-an-android-recyclerview-842e56adbfd8

How to get data from specific rows only in RecyclerView?

I'm stuck on a little problem.
When I click on a row in my RecyclerView, I'd like to change its color to some other color (i.e.: red).
Then, if I click this row again, I would like to set its color back to the normal one (i.e.: white).
Then, if I click on a second row or n-th row, I would like to do the same.
I've tried to work on the RecyclerView Adapter class, in my ViewHolder I tried some ideas counting user clicks, setting a boolean to check the colored rows, and getAdapterPosition to know what is the row's position... but actually all my tries failed!
Would you please help me with that problem?
It seems that I'm close to the solution, but need a little help
You're going to need to keep track of which items were selected on the list (otherwise any changes to the view will simply be recycled).
Keep a list of selected items within your adapter. In the adapter's onBindViewHolder you can check against the list and if the list contains the view/item, you can color the view accordingly.
Edit: Refer here for a working example
How to properly highlight selected item on RecyclerView?

RecyclerView Item specific attribute OnClick

I'm having hard time making this work.
I have the following scenario - when click on CardView the most inner Image should get visible. On second click should disappear. This works fine.
However I want when I select the second CardView the most inner Image to appear the the Image on the first CardView to disappear.
I have this:
1. CardView generated in XML - the cardview have 2 ImageView inside
2. RecyclerView with CustomAdapter and ViewHolder.
3. When I implement OnClick inside ViewHolder it works for each Item - on click the Image appears and on second it disappears.
However I don't know how to check on which Item the image is visible so I can hide it if another Item is clicked. In other word if I select the second I want the first to be deselected. I don't know how to handle this per position.
Any ideas?
Seems like I was missing the point. I solved the problem simply with:
notifyItemChanged(position);
This redraws the item on this position. Since I have simple show/hide behavior with "hide" on initialization I was just using the hide state in OnBindViewHolder and the redraw did the trick.

Android: how to make only one item of ListView clickable?

I am working on a simple to-do list app, and on the main view I have a list of tasks with a checkmark aside to each, as the image below:
Upon clicking on the checkmark I want the respective task to be removed from the list. I tried to implement this as TextViews (for the tasks) and Buttons (for the checkmark), but I would need to know the number/position of the clicked checkmark (0,1,2 or 3) to remove the correct task from my array. Can I get this some how?
I also thought about implementing the tasks/checkmarks as a ListView, but then I would need to set a onItemClickListener only on the checkmark, and not on the task text. Is this possible?
Any other ideas? Thanks.
Checkbox has a tag property which you can use to set custom data like row number. Something like this should work,
checkbox.setTag(row_number);
So when you click on it, do something like
int rowNum = Integer.parseInt(checkbox.getTag());
removeTaskAt(rowNum);
If you're using a Custom Adapter, you can add a click listener on the check on getView, so the click is only on the checkbox and not on the full item.
The only problem with this is that the scroll may not work if you try to scroll by clicking on the checkbox.

android listview

I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.

Categories

Resources