This is question is based on this answer.
I'm trying to pass a string from my RecyclerView.Adapter
to my fragment.
In my adapter I added the following:
onItemClickListner onItemClickListner;
public void setOnItemClickListner(VideoAdapter.onItemClickListner onItemClickListner) {
this.onItemClickListner = onItemClickListner;
}
public interface onItemClickListner{
void onClick(String str);//pass your object types.
}
I pass the following string once the amount of items in my adapter is less then one (adapter is empty):
onItemClickListner.onClick("TESTING");
Then, in my fragment I add the following:
//I do the following after setting my adapter
videoAdapter.setOnItemClickListner(new VideoAdapter.onItemClickListner() {
@Override
public void onClick(String str) {
Toast.makeText(getActivity(), str, Toast.LENGTH_SHORT).show();
}
});
For some reason the string is empty/null and the crash points to onItemClickListner.onClick("TESTING");
.
Can someone please have a look and see what I might be doing wrong?
Edit:
I call onItemClickListner.onClick("TESTING");
inside my OnMenuItemClickListener
as shown below:
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.delete:
onItemClickListner.onClick("TESTING");
return true;
}
I did not provide my entire fragment because I just add the above inside onCreateView
.