How can I update ActionBar title from Adapter?
I tried this:
((MainActivity) getActivity()).getSupportActionBar().setTitle(getString(R.string.home_item));
but this way only works within fragments. So I do this:
((MainActivity) view.getContext()).getSupportActionBar().setTitle(getString(R.string.home_item));
and get cast exception. I don't know how to do it.
So it is possible to update ActionBar Title from Adapter? Thanks
Maybe something like a callback structure? With this you don't need to pass an instance of your whole
Context
but just the callback.And your Activity implements
AdapterCallback
and pass it to the Adapter likeWith that you can simply call in your Adapter class
pass the activity context in your adapter.
In Myadapter class:
Now use
context
to set the title like: