Is it possible to use default Adapters for RecyclerView? ArrayAdapter, for example (without creating own classes?)
Is there sense to use RecyclerView with just one line of text per item? ListView can do it without any extra classes.
Here is a default ArrayAdapter implementation for the RecyclerView
https://github.com/passsy/ArrayAdapter
Sample implementation:
public class UserAdapter extends ArrayAdapter<User, UserAdapter.ViewHolder> {
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView titleView;
public ViewHolder(final View itemView) {
super(itemView);
titleView = (TextView) itemView.findViewById(R.id.title);
}
}
@Nullable
@Override
public Object getItemId(@NonNull final User user) {
return user.getId();
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
final User item = getItem(position);
holder.titleView.setText(item.getName());
}
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
final View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.itemview_user, parent, false);
return new ViewHolder(view);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With