The slider works but is displayed when I click on its BottomNavigationView!
i want to show after running the application without any click! in start fragment!
startFragment codes:
public class StartFragment extends Fragment {
private List<Users> users = new ArrayList<>();
private List<Product> products = new ArrayList<>();
private Activity activity;
private List<String> sliderImages = new ArrayList<>();
private SliderView sliderView;
private RecyclerView homeRecyclerView;
private RecyclerView.LayoutManager manager;
private RecyclerView.Adapter productAdapter;
public StartFragment(Activity activity, List<Users> users, List<Product> products, List<String> sliderImages) {
this.activity = activity;
this.products = products;
this.users = users;
this.sliderImages = sliderImages;
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frame_start , container ,false);
init(rootView);
return rootView;}
private void init(ViewGroup rootView) {
bindView(rootView);
fillSliderData();
getProducts();
}
private void bindView(ViewGroup rootView) {
sliderView = rootView.findViewById(R.id.slider);
homeRecyclerView = rootView.findViewById(R.id.homeRecyclerView);
manager = new GridLayoutManager(activity,1);
homeRecyclerView.setLayoutManager(manager);
}
private void fillSliderData(){
final StartSliderAdapter startSliderAdapter = new StartSliderAdapter(activity , sliderImages);
sliderView.setSliderAdapter(startSliderAdapter);
sliderView.setIndicatorAnimation(IndicatorAnimationType.WORM);
sliderView.setSliderTransformAnimation(SliderAnimations.DEPTHTRANSFORMATION);
sliderView.startAutoCycle();
}
private void getProducts(){
productAdapter = new ProductListAdapter(activity,products,activity , users);
homeRecyclerView.setAdapter(productAdapter);
}
}
users, product and SliderImages getting from database with Volly!
slider adapter codes:
public class StartSliderAdapter extends SliderViewAdapter<StartSliderAdapter.myHolder>{
List<String> images ;
private Context context;
public StartSliderAdapter(Context context , List<String> images){
this.images = images;
this.context = context;
}
#Override
public myHolder onCreateViewHolder(ViewGroup parent) {
View view = LayoutInflater.from(context)
.inflate(R.layout.slider_item , parent , false);
StartSliderAdapter.myHolder holder = new StartSliderAdapter.myHolder(view);
return holder;
}
#Override
public void onBindViewHolder(myHolder viewHolder, int position) {
byte[] bytes = Base64.decode(images.get(position) , Base64.DEFAULT);
Bitmap i = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
viewHolder.imageView.setImageBitmap(i);
}
#Override
public int getCount() {
return images.size();
}
public class myHolder extends SliderViewAdapter.ViewHolder{
private ImageView imageView;
public myHolder(View view) {
super(view);
imageView =(ImageView) view.findViewById(R.id.startSliderImages);
}
}
}
first image
after click again
Can you tell me my mistake and guide me?
Try and use OnViewCreated instead of private void init(ViewGroup rootView)
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) { {
bindView(rootView);
fillSliderData();
getProducts();
}
Related
I have a nested recyclerview to show the list of foods in each category. When the user clicks the increase or decrease button, the quantity will be updated to the quantity textview and synced to the cart stored in the database, but currently I don't know how to listen for the event when the user clicks these buttons.
Here is my current UI when run:
enter image description here
Here is my fragment:
public class TabOrderFragment extends Fragment {
private static final String ARG_RESTAURANT_ID = "restaurantId";
private int restaurantId;
View view;
RecyclerView menuRecyclerView;
RecyclerView.LayoutManager layoutManager;
ArrayList<Menu> menuArrayList;
MenuAdapter menuAdapter;
public TabOrderFragment() { }
public static TabOrderFragment newInstance(int restaurantId) {
TabOrderFragment fragment = new TabOrderFragment();
Bundle args = new Bundle();
args.putInt(ARG_RESTAURANT_ID, restaurantId);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
restaurantId = getArguments().getInt(ARG_RESTAURANT_ID);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_tab_order, container, false);
if(restaurantId != 0) {
DatabaseHandler databaseHandler = DatabaseHandler.getInstance(getActivity());
menuArrayList = new ArrayList<Menu>();
menuArrayList = databaseHandler.getAllMenuFoodsByIdRestaurant(restaurantId);
menuRecyclerView = view.findViewById(R.id.rcv_foods_menu);
menuAdapter = new MenuAdapter(getActivity().getApplicationContext(), restaurantId);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
menuRecyclerView.setLayoutManager(layoutManager);
menuAdapter.setData(menuArrayList);
menuRecyclerView.setAdapter(menuAdapter);
}
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d("TabOrderFragment", "Restaurant Id = " + restaurantId);
}
Here is my MenuAdapter:
public class MenuAdapter extends RecyclerView.Adapter<MenuAdapter.MenuViewHolder> {
Context context;
private int restaurantId;
private RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
ArrayList<Menu> menuList;
public MenuAdapter(ArrayList<Menu> menuList) {
this.menuList = menuList;
}
public MenuAdapter(Context context, int restaurantId) {
this.context = context;
this.restaurantId = restaurantId;
}
public void setData(ArrayList<Menu> menuList) {
this.menuList = menuList;
notifyDataSetChanged();
}
#NonNull
#Override
public MenuViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_foods_menu, parent, false);
return new MenuViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MenuViewHolder holder, int position) {
Menu menu = menuList.get(position);
holder.txtMenuTitle.setText(menu.getTitle().concat(" (" + String.valueOf(menu.getQuantity()) + ")"));
LinearLayoutManager layoutManager = new LinearLayoutManager(holder.rcvListFoods.getContext(), LinearLayoutManager.VERTICAL, false);
layoutManager.setInitialPrefetchItemCount(menu.getFoods().size());
FoodAdapter foodAdapter = new FoodAdapter(menu.getFoods(), restaurantId);
holder.rcvListFoods.setLayoutManager(layoutManager);
holder.rcvListFoods.setAdapter(foodAdapter);
holder.rcvListFoods.setRecycledViewPool(viewPool);
}
#Override
public int getItemCount() {
if(menuList != null) {
return menuList.size();
}
return 0;
}
public class MenuViewHolder extends RecyclerView.ViewHolder {
private TextView txtMenuTitle;
private RecyclerView rcvListFoods;
public MenuViewHolder(#NonNull View itemView) {
super(itemView);
txtMenuTitle = itemView.findViewById(R.id.txv_menu_title);
rcvListFoods = itemView.findViewById(R.id.rcv_list_foods);
}
}
}
Here is my FoodAdapter:
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder> {
private ArrayList<Food> foodList;
private int restaurantId;
private int userId;
SharedPreferences sharedPreferences;
public FoodAdapter(ArrayList<Food> foodList, int restaurantId) {
this.foodList = foodList;
this.restaurantId = restaurantId;
}
#NonNull
#Override
public FoodViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
sharedPreferences = fragmentActivity.getSharedPreferences("currentUser", Context.MODE_PRIVATE);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_food, parent, false);
return new FoodViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull FoodViewHolder holder, int position) {
Food food =foodList.get(position);
Picasso.get().load(food.getThumbImage()).into(holder.foodThumbImage);
holder.foodName.setText(food.getName());
holder.foodDescription.setText(food.getDescription());
double price = Double.parseDouble(food.getPrice());
DecimalFormat formatter = new DecimalFormat("#,###");
holder.foodPrice.setText(formatter.format(price) + "đ");
}
#Override
public int getItemCount() {
if(foodList != null) {
return foodList.size();
}
return 0;
}
public class FoodViewHolder extends RecyclerView.ViewHolder {
private ImageView foodThumbImage;
private TextView foodName;
private TextView foodDescription;
private TextView foodPrice;
private TextView quantity;
private MaterialButton increaseBtn;
private MaterialButton decreaseBtn;
private ItemClickListener itemClickListener;
public FoodViewHolder(#NonNull View itemView) {
super(itemView);
foodThumbImage = itemView.findViewById(R.id.image_food);
foodName = itemView.findViewById(R.id.txv_food_name);
foodDescription = itemView.findViewById(R.id.txv_food_description);
foodPrice = itemView.findViewById(R.id.txv_food_price);
quantity = itemView.findViewById(R.id.txv_quantity);
increaseBtn = itemView.findViewById(R.id.btn_increase);
decreaseBtn = itemView.findViewById(R.id.btn_decrease);
}
}
in your food adapter's onBindViewHolder method use
holder.increaseBtn.setOnClickListener{
onIncreaseClick()
}
while create an interface like
interface Listener{
public void onIncreaseClick();
public void onDecreaseClick();
}
and implement your interface in your activity or fragment or viewmodel where you can listen for the click event
What you can do generally when you have something like that, is to create an interface for the interaction with the Recycler view:
interface Interaction {
public void onFoodClick(Food food)
}
Then you add an instance of this interface in your recycler view adapter, and you let your activity or fragment implement this interface, please find a good explanation here: https://stackoverflow.com/a/31671289/7334951
I am adding data into an addToSepetims arraylist and I want to use it in another fragment but I cant get this arraylist
public class productAdapter extends RecyclerView.Adapter<productAdapter.ViewHolder> {
ArrayList<product_bilgileri> product_bilgileris = new ArrayList<product_bilgileri>();
LayoutInflater layoutInflater;
Context context;
ArrayList<AddToSepetim> addToSepetims = new ArrayList<AddToSepetim>();
public productAdapter(ArrayList<product_bilgileri> product_bilgileris, Context context) {
this.product_bilgileris = product_bilgileris;
this.context = context;
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.productName.setText(product_bilgileris.get(position).getProductname());
holder.description.setText(product_bilgileris.get(position).getDescription());
holder.imageView.setImageDrawable(context.getResources().getDrawable(product_bilgileris.get(position).getImage()));
holder.ratingBar.setRating((product_bilgileris.get(position).getRating()));
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String a =holder.productName.getText().toString();
String b =holder.description.getText().toString();
int c = R.drawable.iphone5;
//Toast.makeText(context, ""+a, Toast.LENGTH_SHORT).show();
addToSepetims.add(new AddToSepetim(a,b,c));
}
});
}
This is Where I want to use addToSepetims arraylist :
public class SepetimFragment extends Fragment {
RecyclerView recyclerView;
ArrayList<AddToSepetim> addToSepetims = new ArrayList<AddToSepetim>();
public SepetimFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_sepetim, container, false);
recyclerView = view.findViewById(R.id.products_recylerview);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager);
SepetimAdapter sepetimAdapter = new SepetimAdapter(addToSepetims,getActivity());
recyclerView.setAdapter(sepetimAdapter);
return view;
}
}
I have also SepetimAdapter Class
public class SepetimAdapter extends RecyclerView.Adapter<SepetimAdapter.ViewHolder> {
ArrayList<AddToSepetim> addToSepetims = new ArrayList<AddToSepetim>();
LayoutInflater layoutInflater;
public SepetimAdapter(ArrayList<AddToSepetim> addToSepetims, Context context) {
this.addToSepetims = addToSepetims;
this.context = context;
}
Context context;
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.row_product_sepetim,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.productName.setText(addToSepetims.get(position).getProductname());
holder.description.setText(addToSepetims.get(position).getDescription());
holder.imageView.setImageDrawable(context.getResources().getDrawable(addToSepetims.get(position).getImage()));
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// addToSepetims.remove(addToSepetims.get(position));
}
});
}
#Override
public int getItemCount() {
return addToSepetims.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView productName,description;
ImageView imageView;
Button button;
public ViewHolder(#NonNull View itemView) {
super(itemView);
productName = itemView.findViewById(R.id.product_Name);
description = itemView.findViewById(R.id.descripton);
imageView = itemView.findViewById(R.id.product_pic);
button = itemView.findViewById(R.id.deleteFromCard);
}
}
}
Second QUESTION :
Product adapter class in onBindViewHolder class :
int c = R.drawable.iphone5;
in this line I want to get holder.imageView instead of "R.drawable.iphone5"
How can I do that ?
You can share data between fragments through a ViewModel:
Add dependency in build.gradle (Module:app) level.
implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0"
implementation "android.arch.lifecycle:runtime:2.2.0"
Create a custom ViewModel class that extends from AndroidViewModel
Here added the list you want to be shared between fragments.
public class MainViewModel extends AndroidViewModel {
private ArrayList<product_bilgileri> products;
public TempViewModel(#NonNull Application application) {
super(application);
}
public ArrayList<product_bilgileri> getProducts() {
return products;
}
public void setProducts(ArrayList<product_bilgileri> products) {
this.products = products;
}
}
Instantiate the ViewModel instance in activity/fragment
// In activity
MainViewModel mViewModel = new ViewModelProvider(this).get(MainViewModel.class);
// In fragment
MainViewModel mViewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class);
Then set the list of data with mViewModel.setProducts(myList) and retrieve it with mViewModel.getProducts()
For more info, check the documentation. Also check this article.
I am newbie in android ViewModel.I have tried to add arraylist item using viewmodel and recyclerview but I couldn't.Please help me..
This is an GalaryViewModel:
class GalleryViewModel extends ViewModel {
private MutableLiveData<ArrayList<String>>fruits ;
MutableLiveData<ArrayList<String>> getFruits() {
if(fruits == null){
fruits = new MutableLiveData<>();
loadFruits();
}
return fruits;
}
private void loadFruits(){
ArrayList<String> fruitList = new ArrayList<>();
fruitList.add("Apple");
fruitList.add("Banana");
fruitList.add("Pinaple");
fruitList.add("Apple");
fruitList.add("Cucamber");
fruitList.add("Cocunut");
fruits.setValue(fruitList);
}
}
This is an GalleryFragment: Where I could not adding the setText value inside the public void onChanged() Function
public class GalleryFragment extends Fragment {
private Context context;
private View view;
private GalleryViewModel galleryViewModel;
private ArrayList<String> fruitList;
public GalleryFragment(Context context, View view, GalleryViewModel galleryViewModel, ArrayList<String> fruitList) {
this.context = context;
this.view = view;
this.galleryViewModel = galleryViewModel;
this.fruitList = fruitList;
}
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
RecyclerView recyclerView = view.findViewById(R.id.gRecyclerView);
final GallaryRecyclerView adapter = new GallaryRecyclerView(context,fruitList);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this.context));
galleryViewModel =
ViewModelProviders.of(this).get(GalleryViewModel.class);
View root = inflater.inflate(R.layout.fragment_gallery, container, false);
final TextView textView = root.findViewById(R.id.text_gallery);
galleryViewModel.getFruits().observe(this, new Observer<ArrayList<String>>() {
#Override
public void onChanged(ArrayList<String> strings) {
textView.setText((CharSequence) strings);
}
// #Override
// public void onChanged(#Nullable String s) {
// textView.setText(s);
// }
});
return root;
}
}
This is an GalleryRecyclerview:
public class GallaryRecyclerView extends RecyclerView.Adapter<GallaryRecyclerView.ViewHolder>{
private Context context;
private ArrayList<String> fruitList;
public GallaryRecyclerView(Context context, ArrayList<String> fruitList) {
this.context = context;
this.fruitList = fruitList;
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView fruitsView;
ViewHolder(#NonNull View itemView) {
super(itemView);
fruitsView = itemView.findViewById(R.id.text_gallery);
}
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.fragment_gallery,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.fruitsView.setText(fruitList.get(position));
}
#Override
public int getItemCount() {
return fruitList.size();
}
}
You just have to instantiate fruitList inside onChanged method.
#Override
public void onChanged(ArrayList<String> strings) {
this.fruitList = strings;
}
i am trying to add a recyclerview on a fragment
fragments code:
public class MediaPlayerController extends Fragment{
private static final String TAG = "MediaPlayerController";
private RecyclerView recyclerViewb;
private RecycleViewAdapter myAdapter;
private ArrayList<String> myRecordings = new ArrayList<>();
//private DBHelper dbHelper;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
Log.d(TAG, "onCreateView: started");
View v = inflater.inflate(R.layout.media_player_area, container, false);
recyclerViewb = (RecyclerView)v.findViewById(R.id.recyclerViewXml);
//dbHelper = new DBHelper(v.getContext(), null, null, 1);
myRecordings.add("hau");
myRecordings.add("hau2");
myRecordings.add("hau3");
myRecordings.add("hau4");
myRecordings.add("ha5");
myRecordings.add("hau23");
myRecordings.add("ha31u");
myRecordings.add("haudsa");
System.out.println("what does this print?"+myRecordings);
myAdapter = new RecycleViewAdapter(v.getContext(), myRecordings);
recyclerViewb.setAdapter(myAdapter);
recyclerViewb.setLayoutManager(new LinearLayoutManager(v.getContext()));
Log.d(TAG, "onCreateView: returned");
return v;
}
in the logs i see that that it doesn't even get to the RecycleViewAdapter sections of code at all the fragment is completely blank
i get not errors as well
public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.ViewHolder>{
private static final String TAG = "RecycleViewAdapter";
private Context mContext;
private ArrayList<String> mRecName = new ArrayList<>();
public RecycleViewAdapter(Context mContext, ArrayList<String> mRecName) {
this.mContext = mContext;
this.mRecName = mRecName;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
Log.d(TAG, "onCreateViewHolder: i am here");
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_row_recycle, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(#NonNull final ViewHolder holder, int position) {
Log.d(TAG, "onBindViewHolder: called");
holder.recTxt.setText(mRecName.get(position).toString());
holder.parentLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext, "sas gamaw", Toast.LENGTH_LONG);
}
});
}
#Override
public int getItemCount() {
return 0;
}
public class ViewHolder extends RecyclerView.ViewHolder{
RelativeLayout parentLayout;
TextView recTxt;
public ViewHolder(View itemView) {
super(itemView);
recTxt = itemView.findViewById(R.id.recTextView);
parentLayout = itemView.findViewById(R.id.parentLayoutXml);
}
}
}
in the logs it only displays oncreateView started and the myRecordings arraylist
onCreateView: started
I/System.out: what does this print?[hau, hau2, hau3, hau4, ha5,
hau23, ha31u, haudsa]
MediaPlayerController: onCreateView: returned
i can't think of what is going wrong :/ please help out
i also want to add that i am fairly new to android studio thanks
your code problem it is in Recycler Adapter in getItemCount() method,
You don't return any Item , you must change it to :
#Override
public int getItemCount() {
return mRecName.size();
}
I'm learning android and I'm just new to this concept.
This is my adapter class. It shows an error saying that the CategoryList is not an enclosing class. I'm unable to understand the error. Please help me in uderstanding it. Thanks in advance.
public class CategoryAdapter extends RecyclerView.Adapter<CategoryHolder> {
private final Context context;
private final List<Category> categories;
public CategoryAdapter(Context context, List<Category> categories) {
this.context = context;
this.categories = categories;
}
#Override
public CategoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
// Here it's showing an error: CategoryList is not an enclosing class.
return new CategoryHolder(layoutInflater, parent);
}
#Override
public void onBindViewHolder(CategoryHolder holder, int position) {
final Category category = categories.get(position);
holder.bind(category);
}
#Override
public int getItemCount() {
return categories.size();
}
}
This is my first fragment. It contains the list of categories such as google, facebook etc. On click on any of these items, it should open another fragment with some detail regarding the category.
public class CategoryList extends Fragment {
private RecyclerView recyclerView;
public CategoryList() { }
private void updateUI() {
List<Category> categories = new ArrayList<>();
categories.add(new Category(1L, "Google", "Hello world!! This is Google."));
categories.add(new Category(2L, "Facebook", "Hello world!! This is Facebook"));
categories.add(new Category(3L, "WhatsApp", "Hello world!! This is WhatsApp"));
categories.add(new Category(4L, "LinkedIn", "Hello world!! This is LinkedIn"));
CategoryAdapter categoryAdapter = new CategoryAdapter(getActivity(), categories);
recyclerView.setAdapter(categoryAdapter);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_category_list, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.category_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
updateUI();
return view;
}
public class CategoryHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private Category category;
private final TextView name;
private final TextView description;
public CategoryHolder(LayoutInflater inflater, ViewGroup parent) {
super(inflater.inflate(R.layout.category_layout, parent, false));
this.name = (TextView) itemView.findViewById(R.id.category_name);
this.description = (TextView) itemView.findViewById(R.id.category_description);
}
public void bind(final Category category) {
this.category = category;
this.name.setText(category.getName());
this.description.setText(category.getDescription());
}
#Override
public void onClick(View v) {
Fragment fragment = CategoryDetail.getInstance(category);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction()
.add(R.id.detail_container, fragment)
.commit();
}
}
}
This is the fragment that contains the detail of the category. For now I've not written anything in updateUI() method.
public class CategoryDetail extends Fragment {
private Category category;
public CategoryDetail() { }
public static CategoryDetail getInstance(Category category) {
CategoryDetail categoryDetail = new CategoryDetail();
categoryDetail.category = category;
return categoryDetail;
}
private void updateUI() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.category_detail, container, false);
updateUI();
return view;
}
}
You didn't create a ViewHolder class. Based on your code, you would want to create
public class CategoryHolder extends RecyclerView.ViewHolder {
public CategoryHolder(View view) {
//code for the constructor for the ViewHolder goes here.
}
}