I made a tabview for my app and added recyclerview in one of the tabs it works properly but I cannot make it clickable. I want to make it clickable so that on clicking a specific item in the list it takes you to a new activity. I have created new activities as destination for the clicks. There are posts about how to do it in a normal activity and those do not seem to work for me when I tried to implement them after modification
my Listadapter.java
package com.example.android.split;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ListAdapter extends RecyclerView.Adapter {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent,false);
return new ListViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
((ListViewHolder) holder).bindView(position);
}
@Override
public int getItemCount() {
return Data.iname.length;
}
private class ListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private TextView mItemText;
public ListViewHolder(View itemView){
super(itemView);
mItemText = (TextView) itemView.findViewById(R.id.itemText);
itemView.setOnClickListener(this);
}
public void bindView(int position){
mItemText.setText(Data.iname[position]);
}
public void onClick(View view){
}
}
}
my fragment code
package com.example.android.split;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HeaderViewListAdapter;
/**
* A simple {@link Fragment} subclass.
*/
public class tab1 extends Fragment {
public tab1() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_tab1, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.listRecyclerview);
ListAdapter listAdapter = new ListAdapter();
recyclerView.setAdapter(listAdapter);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
return view;
}
}