Reputation: 695
I've created a custom adapter to handle a RecyclerView.
For some reason, the only methods that I can call from it after it has been initialised, are the ones that are overridden. Can anyone explain why this is? I have no idea!
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private List<Item> items;
public static class ViewHolder extends RecyclerView.ViewHolder {
private ImageView icon;
private TextView text;
public ViewHolder(View item) {
super(item);
text = (TextView) itemView.findViewById(R.id.t);
icon = (ImageView) itemView.findViewById(R.id.i);
}
....
}
public CustomAdapter(List<Item> items) {
this.items = items;
}
@Override
public CustomAdapter.ViewHolder onCreateViewHolder(ViewGroup container, int type) {
View v = LayoutInflater.from(container.getContext())
.inflate(R.layout.fragment, container, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//method content
}
// EVERY METHOD I HAVE WRITTEN FROM HERE ONWARDS GOES UNDETECTED
public int getCount() {
return items.size();
}
}
i.e. when I instantiate an instance of the adapter:
private RecyclerView.Adapter adapter = new CustomAdapter(items);
and then I try to call adapter.getCount()
it does not detect getCount()
.
getCount()
does not come up in the autocomplete options when I start to type after 'adapter'.
getCount()
shows an error, which just says 'Cannot Resolve Method' and getCount()
in the CustomAdapter
class shows that it is never used. This applies to all methods which do not have @override above them.
It is as if the methods don't exist. I cannot call them, but they are there. I am completely baffled!
Upvotes: 0
Views: 30
Reputation: 30985
change
private RecyclerView.Adapter adapter = new CustomAdapter(items);
to
private CustomAdapter adapter = new CustomAdapter(items);
Upvotes: 2