How Do I Open Different Tab Fragment When I Clicked on Different Item in Home Activity Adapter

I am Able to open different activity when I clicked on Item. I want to open Specific Tab Fragment for specific Service Items. When I click Item One it will open fragment one (Tab One). When I click Item 2 it will Fragment Two (Tab Two) and so on for different Items. How can I do this here is my code:\

package com.example.hira.bengalmovers;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;

import java.util.ArrayList;

public class HomeRecyclerAdapter extends RecyclerView.Adapter implements Filterable {

Context c;
ArrayList<Homeservicelist> homeservicelists, filterList;
CustomFilter filter;

HomeRecyclerAdapter(Context c, ArrayList<Homeservicelist> homeservicelists) {
    this.c = c;
    this.homeservicelists = homeservicelists;
    this.filterList = homeservicelists;
}

@NonNull
@Override
public HomeRecyclerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.homeervicelist,null);
    return new HomeRecyclerHolder(v);
}

@Override
public void onBindViewHolder(@NonNull HomeRecyclerHolder holder, int position) {
    holder.mImageIV.setImageResource(homeservicelists.get(position).getImg());
    holder.mTitleTV.setText(homeservicelists.get(position).getTitle());

    holder.setItemClickListener(new HomeRecyclerHolder.ItemClickListener() {
        @Override
        public void onItemClick(View v, int pos) {
            final Intent intent;
            if (homeservicelists.get(pos).getTitle().equals("Home Shifting Service")){
                intent =  new Intent(c, ServicetabActivity.class);
                v.getContext().startActivity(intent);
            }
            else if (homeservicelists.get(pos).getTitle().equals("Office Shifting Service")){
                intent =  new Intent(c, HomeShiftingFragment.class);
                v.getContext().startActivity(intent);
            }
        }
    });
}

@Override
public int getItemCount() {
    return homeservicelists.size();
}

@Override
public Filter getFilter() {
    if (filter == null){
        filter = new CustomFilter(filterList,this);
    }
    return filter;
}

}

Sign In or Register to comment.