How to do you implement a recyclerview onClick in a Fragment? - android

My question is similar to this one.
Best approach to communicate between Fragment/Activity and RecyclerView.Adapter?
I know how to implement an onClickListener, an Interface and an OnItemSelected method in the corresponding activity when the user clicks on a button in a Fragment. I have a fragment with an array list. By clicking on each item in the array list in the fragment, an ExoPlayer will open in a new activity or a fragment. As I understand it, onItemClickListener doesn't work with Recyclerview. How do I set the onClick method to the items in the list? Also, do I set onClick outside of RecyclerView? This is my RecyclerView adapter class. Should the interface take additional parameters? Thank you in advance.
public class StepsAdapter extends RecyclerView.Adapter {
private static final String TAG = StepsAdapter.class.getSimpleName();
private ArrayList<Steps> stepsList = new ArrayList<Steps>();
private StepsAdapter.StepsAdapterOnClickHandler mClickHandler;
/**
* The interface that receives onClick messages.
*/
public interface StepsAdapterOnClickHandler {
void onClick(Steps stepClick);
}
/**
* Creates a StepsAdapter.
*
* #param clickHandler The on-click handler for this adapter. This single handler is called
* when an item is clicked.
*/
public StepsAdapter(StepsAdapterOnClickHandler clickHandler,ArrayList<Steps> stepsList) {
mClickHandler = clickHandler;
this.stepsList = stepsList;
}
/**
* Cache of the children views for a steps list item.
*/
public class StepsAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
#BindView(R.id.step_short_desc)
public TextView stepShortDescription;
#BindView(R.id.step_description)
public TextView stepDescription;
public StepsAdapterViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
view.setOnClickListener(this);
}
/**
* This gets called by the child views during a click.
*
* #param v The View that was clicked
*/
#Override
public void onClick(View v) {
int adapterPosition = getAdapterPosition();
Steps stepClick = stepsList.get(adapterPosition);
mClickHandler.onClick(stepClick);
}
}
#Override
public StepsAdapter.StepsAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
Context context = viewGroup.getContext();
int layoutIdForListItem = R.layout.steps_list_item;
LayoutInflater inflater = LayoutInflater.from(context);
boolean shouldAttachToParentImmediately = false;
View view = inflater.inflate(layoutIdForListItem, viewGroup, shouldAttachToParentImmediately);
return new StepsAdapter.StepsAdapterViewHolder(view);
}
#Override
public void onBindViewHolder(StepsAdapter.StepsAdapterViewHolder holder, int position) {
//Binding data
final Steps stepsView = stepsList.get(position);
holder.stepShortDescription.setText(stepsView.getStepShortDescription());
holder.stepDescription.setText(stepsView.getStepDescription());
}
#Override
public int getItemCount() {
return stepsList.size();
}
public void setStepsList(ArrayList<Steps> mStepsList) {
this.stepsList = mStepsList;
notifyDataSetChanged();
}
}
The corresponding fragment. Is the click method implemented correctly?
public class StepsListFragment extends Fragment implements StepsAdapter.StepsAdapterOnClickListener {
// Tag for logging
private final String TAG = StepsListFragment.class.getSimpleName();
#BindView(R.id.recyclerview_steps)
RecyclerView mRecyclerView;
ArrayList<Steps> stepsArrayList;
Recipes recipes;
// Final Strings to store state information about the list of steps and list index
public static final String STEPS_LIST_INDEX = "list_index";
// Define a new interface OnStepsClickListener that triggers a callback in the host activity
OnStepClickListener mCallback;
// OnStepsClickListener interface, calls a method in the host activity named onStepSelected
public interface OnStepClickListener {
void onClick(Steps stepClick);
}
// Override onAttach to make sure that the container activity has implemented the callback
#Override
public void onAttach(Context context) {
super.onAttach(context);
// // This makes sure that the host activity has implemented the callback interface
// // If not, it throws an exception
try {
mCallback = (OnStepClickListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement OnStepSelectedListener");
}
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the fragment
*/
public StepsListFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// //Inflate the Steps fragment layout
View rootView = inflater.inflate(R.layout.fragment_steps, container, false);
// // Bind the views
ButterKnife.bind(this, rootView);
Bundle bundle = this.getArguments();
if (bundle != null) {
recipes = getArguments().getParcelable("Recipes");
stepsArrayList = new ArrayList<>();
stepsArrayList = recipes.getRecipeSteps();
}
if (savedInstanceState != null) {
//Restore the fragment's state here
stepsArrayList = savedInstanceState.getParcelableArrayList(STEPS_LIST_INDEX);
}
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
Log.i("listSteps", stepsArrayList.size() + "");
StepsAdapter stepsAdapter = new StepsAdapter(this, stepsArrayList);
mRecyclerView.setAdapter(stepsAdapter);
// Return the root view
return rootView;
}
public void onClick(Steps stepClick){
mCallback.onClick(stepClick);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveIn`enter code here`stanceState(outState);
//Save the fragment's state here
outState.putParcelableArrayList(STEPS_LIST_INDEX, stepsArrayList);
super.onSaveInstanceState(outState);
} }

The best way to implement click function on each item of recyclerview is initialise onClickListener when the view is populated inside in the recyclerview viewholder. Then in the onClick method, use a custom interface/listener to catch the click activity in your parent fragment/activity.
eg: create a custom interface like this;
public interface RecyclerviewOnClickListener{
void recyclerviewClick(int position);
}
Now implement this interface in your parent activity/fragment containing the recyclerview. Suppose your fragment name is ChatFragment. Then,
public class ChatFragment extends Fragment implements RecyclerviewOnClickListener{
.
.
}
This will implement the function onClick(int position) in your fragment. In your adapter constructor, you should create a field for the RecyclerviewOnClickListener. Suppose your adapter name is ChatAdapter, then
Adapter Constructor.
public ChatAdapter(RecyclerviewClickListener listener, .....<other params>){
this.listener = listener;
}
In your fragment, you can initialise your adapter like the following
ChatAdapter adapter = new ChatAdapter(this, <any additional params>);
You should pass the same instance of 'listener' to your viewholder also, and initialise the listener there also
Now in your recyclerview ViewHolder, you can set view.setOnClickListener(new OnClickListener{
this.listener.recyclerviewClick(getAdapterPosition())
});
The getAdapterPosition() function returns the position of the click in the recyclerview, which will get a callback in the recyclerviewClick() function in your fragment.
About the number of parameter you are passing, you can use as much as you want, but for a click function in recyclerview, the ideal way is to use only one param which the position. Now you can modify the contents in the list that you are passing from your fragment to adapter and call notifyDataSetChanged() which will update the recyclerview. Hope it's clear.

Try this inside OnBindviewHolder
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//code here
}

Related

Android - RecyclerView pass value into its own activity [duplicate]

My fragment:
public class FragmentSort extends Fragment {
#BindView(R.id.sortRecyclerView)
RecyclerView sortRecyclerView;
protected RecyclerView.Adapter adapter;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(layoutResId, container, false);
adapter = new StoreListItemAdapter(getActivity(), collection);
sortRecyclerView.setAdapter((RecyclerView.Adapter) adapter);
return rootView;
}
#Subscribe
public void onStoreClickEvent(Store store) {
Debug.d(TAG, "onStoreClickEvent: store = " + store);
handleFilterItemSelect(store.getAddress());
}
}
Here my custom adapter:
public class StoreListItemAdapter extends RecyclerView.Adapter {
private Context context;
private List<?> data = new ArrayList<>();
public DataBindingRecyclerViewAdapter(Context context, List<?> data) {
this.context = context;
this.data = data;
}
public void onClick(Store store) {
EventBus.getDefault().post(store);
}
}
When click on some item in list then call method onClick().
So I need my fragment to handle click of item.
To to do this I use EventBus.
After click I call
EventBus.getDefault().post(store);
And as result in fragment call method:
onStoreClickEvent(Store store)
So this is my model to communicate between my custom fragment and my custom adapter.
It's work. Fine.
The quesion is: Is this a best approach for communicate between fragment and adapter?
P.S. My custom adapter can use by fragment, activity or custom view.
An alternative would be to create a listener interface like this:
public interface OnStoreItemClickListener {
public void onStoreItemClicked(Store item);
}
Then, in your Adapter, you declare a field of type OnStoreItemClickListener and you create a setter method for it.
When you detect a click, you simply check if your listener is set and call the onStoreItemClicked() method.
You can register a listener via the setter from wherever you need.

Best approach to communicate between Fragment/Activity and RecyclerView.Adapter?

My fragment:
public class FragmentSort extends Fragment {
#BindView(R.id.sortRecyclerView)
RecyclerView sortRecyclerView;
protected RecyclerView.Adapter adapter;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(layoutResId, container, false);
adapter = new StoreListItemAdapter(getActivity(), collection);
sortRecyclerView.setAdapter((RecyclerView.Adapter) adapter);
return rootView;
}
#Subscribe
public void onStoreClickEvent(Store store) {
Debug.d(TAG, "onStoreClickEvent: store = " + store);
handleFilterItemSelect(store.getAddress());
}
}
Here my custom adapter:
public class StoreListItemAdapter extends RecyclerView.Adapter {
private Context context;
private List<?> data = new ArrayList<>();
public DataBindingRecyclerViewAdapter(Context context, List<?> data) {
this.context = context;
this.data = data;
}
public void onClick(Store store) {
EventBus.getDefault().post(store);
}
}
When click on some item in list then call method onClick().
So I need my fragment to handle click of item.
To to do this I use EventBus.
After click I call
EventBus.getDefault().post(store);
And as result in fragment call method:
onStoreClickEvent(Store store)
So this is my model to communicate between my custom fragment and my custom adapter.
It's work. Fine.
The quesion is: Is this a best approach for communicate between fragment and adapter?
P.S. My custom adapter can use by fragment, activity or custom view.
An alternative would be to create a listener interface like this:
public interface OnStoreItemClickListener {
public void onStoreItemClicked(Store item);
}
Then, in your Adapter, you declare a field of type OnStoreItemClickListener and you create a setter method for it.
When you detect a click, you simply check if your listener is set and call the onStoreItemClicked() method.
You can register a listener via the setter from wherever you need.

open a Fragment by clicking on a recyclerview item and move to this fragment

i'm trying to open a Fragment by clicking on a recyclerview item, what i'm getting after clicking on item is both fragment toghter, i see the image from the fragment that i want to go to after the clicking on my recyclerview..Does anyone have any idea what i'm doing wrong?
public class MainActivity extends AppCompatActivity {
private FragmentManager manger;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<Chat> chatList = new ArrayList<>();
chatList.add(new Chat("send post card", " ", R.drawable.sentpostcard));
chatList.add(new Chat("send greeting card", "happy holiday", R.drawable.greetingcard));
chatList.add(new Chat("special designs", "choose a card", R.drawable.special));
ChatAdapter adapter = new ChatAdapter(chatList);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.chatList);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
}
// 1
public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ChatViewHolder>{
// 7
private ArrayList<Chat> chats;
// 8
public ChatAdapter(ArrayList<Chat> chats) {
this.chats = chats;
}
// 10
#Override
public ChatViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.layout.chat_list_item, parent, false); // false == do not attach to root
return new ChatViewHolder(v);
}
// 11
#Override
public void onBindViewHolder(ChatViewHolder holder, int position) {
holder.bind( chats.get(position) );
}
// 9
#Override
public int getItemCount() {
return chats.size();
}
// 2
public class ChatViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//4
private TextView textName, textChat;
private ImageView imageChat;
//we need to remember a chat for each view holder and we bind the chat object using the bind function
//this will be useful later in the onClick Listener
private Chat c;
// view is the layout view ==> it contains all of the view in the layout file
// 3
public ChatViewHolder(View itemView) {
super(itemView);
// 5
textName = (TextView) itemView.findViewById(R.id.textName);
textChat = (TextView) itemView.findViewById(R.id.textChat);
imageChat = (ImageView) itemView.findViewById(R.id.imageChat);
// 12
itemView.setOnClickListener(this);
}
// 6
public void bind(Chat chat){
c = chat;
textName.setText(chat.getName());
textChat.setText(chat.getText());
imageChat.setImageResource(chat.getImage());
}
#Override
public void onClick(View v) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new FragA()).commit();
}
}
}
}
Would be nice to see you layout xml, but from what I can see:
Your recycler view is not inside a fragment - it is inside the MainActivity. You set it with setContentView(R.layout.activity_main);
When you do
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new FragA()).commit();
you put your new fragment in the fragment_container view group. But this does not affect the activity at all. So, you end up with both views visible.
There are two ways to fix this:
The easy and hacky one - set solid background (i.e android:background="#android:color/black") to your fragment and add android:clickable="true" to it's root layout. Then you won't be able to see or interact with the activity that will be beneath your fragment.
More proper way - put your recycler view in a fragment, put that fragment in the fragment_container with getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, recyclerFragment).commit();. Then it will be replaced with your new fragment on item click when you call getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new FragA()).commit();
To be able to go back to the recycler view you will also need to call addToBackStack method

onCreateViewHolder is never called

I am trying to use recyclerView which is inside a fragment.This is fragment is nested inside the viewPager.
public class UniversityDetail extends Fragment {
RecyclerView universityDetailView;
//need to set Adapter
public static UniversityDetail newInstance(){
return new UniversityDetail();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fragment_university_lsit,container,false);
universityDetailView = (RecyclerView)view;
setupViews();
return view;
}
private void setupViews(){
//set the adapter
UniversityDetailAdapter detailAdapter = new UniversityDetailAdapter(new ArrayList<UniversityDetails>());
universityDetailView.addItemDecoration(new RecyclerListDecorater(getActivity()));
universityDetailView.setAdapter(detailAdapter);
universityDetailView.setLayoutManager(new LinearLayoutManager(getActivity()));
universityDetailView.setHasFixedSize(false);
}
public RecyclerView getRecyclerView(){
return this.universityDetailView;
}
}
This is the fragment which i want to be inside the viewPager.It returns a recyclerView from onCreateView.
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scroll"
android:paddingBottom="8dp"
android:paddingTop="?attr/actionBarSize"
android:scrollbars="vertical">
fragment_university_lsit.xml
recyclerView uses below adapter.
public class UniversityDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<UniversityDetails> universityDetails;
private static Map<String,String> admissionRecommendation;
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((DetailHolder)holder).bind(universityDetails.get(position));
}
#Override
public int getItemCount() {
return universityDetails.size();
}
public UniversityDetailAdapter(List<UniversityDetails> details){
this.universityDetails = details;
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
Log.d("CreateUniveristyDetail", "onCreateViewHolder: detail called");
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.detail_fragment,parent,false);
return new DetailHolder(itemView);
}
}
DetailHolder is the class extends ReyclerView.ViewHolder and its implementation is irrelevant here.
The adapter list is upated from handler and notifyDataSetChanged()
private void setup(){
mHandler = new Handler(Looper.getMainLooper()){
#Override
public void handleMessage(Message message){
if(message.what == ConnectionHandler.DETAILMSG){
Log.d("detail handle message", "handleMessage: Called");
List<UniversityDetails> details = (List<UniversityDetails>)message.obj;
UniversityDetailAdapter adapter = (UniversityDetailAdapter)universityDetail.getRecyclerView().getAdapter();
adapter.addAll(details);
adapter.notifyDataSetChanged();
Log.d("size", "handleMessage: " + adapter.getItemCount());
}
}
};
}
Fragment is created in activity..
private void setupNavigation(){
ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
universityDetail = UniversityDetail.newInstance();
pagerAdapter.addFragment(universityDetail);
mViewPager.setAdapter(pagerAdapter);
//setup the fragment transaction.
headerTab.setViewPager(mViewPager,0);
//no need to add to back stack
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.view_pager,universityDetail);
transaction.commit();
}
Implementation of DetailHolder
public class DetailHolder extends RecyclerView.ViewHolder{
CardView admissionGeneral;
public View root;
public DetailHolder (View itemView){
super(itemView);
root = itemView;
admissionGeneral = (CardView)root.findViewById(R.id.admission_general);
}
public void bind(UniversityDetails detail){
Log.d("detail bind", "bind: binding to recyclerView");
}
}
here the log of adapter.getItemCount(); return 3; thats means something is being added and onCreateViewHolder is supposed to be called but it never is.
The weird thing is i have implemented another recyclerAdapter is the sameProject and its working perfectly fine.
This problem would be easier to answer if you could show how the universityDetail was assigned from whatever class contains the Handler usage.
It's also not clear how message.obj is able to be cast to a List.
I believe you are using a different instance of the Fragment there than the one that you want to update.
So, you know this line is good
List<UniversityDetails> details = (List<UniversityDetails>)message.obj;
because you see 3 in the output when you do this
Log.d("size", "handleMessage: " + adapter.getItemCount());
Now, these lines could likely be the problem.
UniversityDetailAdapter adapter = (UniversityDetailAdapter)universityDetail.getRecyclerView().getAdapter();
adapter.addAll(details);
adapter.notifyDataSetChanged();
Firstly, there is no addAll method to RecyclerView.Adapter. So I'm not sure how that compiled. Anyways...
Try to keep cross-class references to a minimum. Here, we expose only the method to add the details rather than the entire RecyclerView.
Then, for RecyclerViews, you should notify only the data that was inserted rather than all of it using notifyItemRangeInserted
public class UniversityDetailFragment extends Fragment {
private RecyclerView universityDetailView;
private UniversityDetailAdapter detailAdapter;
private List<UniversityDetails> details = new ArrayList<UniversityDetails>();
...
public void setupViews() {
detailAdapter = new UniversityDetailAdapter(details);
// etc...
}
public void addDetails(List<UniversityDetails> details) {
int curSize = detailAdapter.getItemCount();
this.details.addAll(details);
detailAdapter.notifyItemRangeInserted(curSize, details.size());
}
}
And then just use the instance of your Fragment
if(message.what == ConnectionHandler.DETAILMSG){
Log.d("detail handle message", "handleMessage: Called");
List<UniversityDetails> details = (List<UniversityDetails>) message.obj;
universityDetail.addDetails(details);
Another recommendation would be to use the correct generic type for the holder class to avoid unnecessary casts.
public class UniversityDetailAdapter extends RecyclerView.Adapter<DetailHolder>

ViewPager onPageSelected for first page

So it appears that when using a ViewPager, the onPageSelected listener does not get called for the first page same issue as this.
I have some logic that populates some more expensive UI elements for the currently selected page and this works when page is changed, but it doesn't work for the first page.
If I set the current item after the listener, the callback gets fired for the first page, but the view has not been initialized yet, so I can't manipulate it:
// Inside PagerAdapter.instantiateItem
ViewHolder vh = new ViewHolder();
cursor.moveToPosition(position);
vh.view = adapter.newView(context, cursor, null);
// Set position as tag so we can retrieve it with findViewByTag
vh.view.setTag(position);
((ViewPager) collection).addView(vh.view,0);
return vh;
// Inside MyActivity.onCreate
pagerAdapter = new SingleMessagePagerAdapter(this, cursor);
pager = (ViewPager)findViewById(R.id.message_pager);
pager.setAdapter(pagerAdapter);
pager.setOnPageSelectedListener(this);
pager.setCurrentItem(selectedItem);
// Inside MyActivity.onPageSelected
// Retrieve tagged view
View view = pager.findViewWithTag(position);
Here view ends up being null because PagerAdapter.instantiateItem has not yet been run. So I guess my question is, at which point in the activity lifecycle can I be certain that the ViewPager has initialized the view? I tried doing this inside Activity.onAttachedToWindow and Activity.onResume but it appears both of these get fired before PagerAdapter.instantiateItem.
I'm wondering why you don't just have the logic you mention in the Fragment itself rather than the hosting Activity. ViewPager buffers a couple of fragments either side of the current one so they're set up in the background and ready to go when the user swipes to them. Putting the logic in onPageSelected would mean bypassing this functionality and not doing the heavy lifting until the user swipes to the page.
Assuming for some reason you can't do the above, why not use an Interface with a callback function. Trigger the callback in the fragment's onCreateView function to let the Activity know it's fully instantiated.
try to use fragments!
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter() {
super(getSupportFragmentManager());
}
#Override
public Fragment getItem(int i) {
Fragment fr = null;
if (i==0)
fr = new sec0frag();
else if (i==1)
fr = new sec1frag();
else if (i==2)
fr = new sec2frag();
return fr;
}
#Override
public int getCount() {
return 3;
}
}
and create 3 fragments classes
e.g. :
public static class sec0frag extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// here is initialize for first time to view pages.!
}
}
My solution was to extend pager adapter and create an interface inside it. Then make the adapter call the interface only once after creating the adapter. Inside interface callback you can call onPageChanged method without having nullpointerexception. Add this class to your project and extend your adapter from it. Dont forget to set listener to adapter before setting adapter to viewpager. Adapter class below:
public abstract class ExtendedPagerAdapter extends FragmentPagerAdapter {
private boolean instantiated;
private AdapterListener adapterListener;
public interface AdapterListener {
void onAdapterInstantiated();
}
public ExtendedPagerAdapter(FragmentManager fragmentManager) {
this(fragmentManager, null);
}
public ExtendedPagerAdapter(FragmentManager fragmentManager, AdapterListener adapterListener) {
super(fragmentManager);
this.adapterListener = adapterListener;
instantiated = false;
}
#Override
public void finishUpdate(ViewGroup container) {
super.finishUpdate(container);
if (!instantiated) {
instantiated = true;
if (adapterListener != null) {
adapterListener.onAdapterInstantiated();
}
}
}
public void setAdapterInstantiatedListener(AdapterListener adapterListener) {
this.adapterListener = adapterListener;
}
}
Activity code:
adapter = new ViewPagerAdapter(getChildFragmentManager());
adapter.setAdapterInstantiatedListener(new ExtendedPagerAdapter.AdapterListener() {
#Override
public void onAdapterInstantiated() {
onPageSelected(viewPager.getCurrentItem());
}
});
viewPager.addOnPageChangeListener(this);
viewPager.setAdapter(adapter);

Categories

Resources