Update View in Activity in response to recycler view item click - android

I have this type of activity layout
In my layout, the yellow portion is my recyclerview, which is currently working as the expandable list.
Now in my scenario, when the user clicks on any item in the recyclerview than the layout changes in the activity shown by, green area and its child in the image.
Is there any way to do so?

Here is the simple example of pass value from recyclerview to activity using eventbus. Try this maybe will help you to solve your problem.

You can use callback method.On click of item update UI using callback method.

Yes you can achieve this easily by using EventBus.

Related

Expandable RecyclerView and custom ui

I'm trying to make a screen that have an expandable categories
each category have items that when clicked i want it to be added to an element in the same screen like this pic
and when the unselect (red one) is pressed it remove it from the list
any ideas on how to implement this or suggestion for similar components
You may try using expanable-recycler-view from bignerdranch, to remove item from view, just
Remove item form data list when red button is pressed and
Notify adapter for change using notifyDataSetChanged()
Hope this help, thank you. :)

Change the recyclerview's focus to certain item position?

So I have a standard RecyclerView that takes a list of posts and displays them to the user. My problem is when the user comes into the activity, I want to be able to change the focus to a particular post.
Ex. User A sees that he has a notification that of someone has liked his/her post. He/she clicks that notification, and it loads the activity of user's post, and then the focus changes to the position of the post that had bee liked.
I pass in the postID to the activity using an intent. I then run the Recycler View, and onBindHolder i try to see if the post's ID matches to the postID I sent in via intent. If it does, I now set the activity's variable postFocusPosition to the position of that post.
Now I'm stuck on what that magic method i need to call in RecyclerView class to actually change the focus to that item position!
Hope someone can help enlighten me on that magic line(s) of code that changes focus!
recyclerView.setAdapter(adapter);// set adapter on recyclerview
recyclerView.scrollToPosition(mSkipTo); //use to focus the item with index
adapter.notifyDataSetChanged();
mProgressDialog.dismiss();
For smooth scrolling effect and to avoid any resizing issue of recyclerview items, you can use
recyclerView.smoothScrollToPosition(itemposition); //you can get this position, from your adapter class through an interface method
As with "scrollToPosition", I was facing resizing issue of recyclerview items.
Note : You could use this method for both horizontal and vertical recyclerview.
just use this
recyclerView.scrollToPosition(position);

RecyclerView: Highlight selected item

I have implemented a RecyclerView and I have set it up to use CAB. But how can I highlight the selected items? If a certain position I checked I stored in a SparseBooleanArray.
My first thought was to store the specific View containg all the elements in my ViewHolder and then in onBindViewHolder set the background somehow to: ?android:attr/activatedBackgroundIndicator
But how can I do that? Is that a useful approach?
I finally solved this by simply adding some minor things:
First of all, the items of the RecyclerView have to use this as background:
android:background="?android:attr/activatedBackgroundIndicator"
Then for the RecyclerView simply call:
setSelected(true); on the indiviual views.
If you want to change the View itself, you need to dispatch adapter.notifyItemChanged(position) and in return, recycler view will call onBind method where you can set the background.
If you don't need to update the view itself, I would suggest using an item decorator.

list view animation

I have a list view with custom adapter. I'm trying to implement following
when a item in the list is clicked, only that item is expanded and show some info.
when it is clicked again, it goes back to the first state. can any one suggest a
way to achieve this.
thanks in advance
Use ExpandableListView.
It can help you.
ExpandableListView can expanded and back to the first state.
Also, you can custom inner layout.(some info)
please use it.

Custom Listener for a ListView item

I have a View with a ListView appended, which actually uses a custom view item done programatically. Inside each list item I have a button which I need to track, to update another item in the view. It is only invalidated when you click on the list item button, not anywhere else in the list item.
So I thought of creating a custom Listener. I trigger it when the button is clicked, but I have no way to access it from the ListView activity.
Is there a way to simulate those setOnItem...Listener's using a custom listener? Thanks in advance
Please see this link to help with how to set onClickListener from within custom ListAdapters.
You can use the myButton.getTag() and myButton.setTag() to put and get data to/from your View/Button.
See this link as well to help with custom ListAdapters.
Here is another good example I found of how to use a custom adapter.

Categories

Resources