1

I want to add the Fast-Scroll-Feature (like in the Android contacts app or in Whatsapp contacts) to my RecyclerView?

I would also use a listview but I need Cards in my app on the same layout!

If implementing fast-scroll to Recyclerview is too difficult, using a ViewStub is also an option, or not?

My RecyclerViewAdapter:

public class SongRecyclerViewAdapter extends RecyclerView.Adapter<SongRecyclerViewAdapter.Holder> {
    private Song[] sSongs;

    public SongRecyclerViewAdapter(Song[] songs) {
        sSongs = songs;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_songview, parent, false);

        Holder holder = new Holder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        //holder.imvSong.setImageResource(R.drawable.standardartwork);
        holder.txvSongTitle.setText(sSongs[position].getTitle());
        holder.txvSongInfo.setText(sSongs[position].getArtists());
    }

    @Override
    public int getItemCount() {
        return sSongs != null ? sSongs.length : 0;
    }

    public class Holder extends RecyclerView.ViewHolder {
        LinearLayout linearLayout;
        ImageView imvSong;
        TextView txvSongTitle;
        TextView txvSongInfo;

        public Holder(View layout) {
            super(layout);

            linearLayout = (LinearLayout) layout;

            imvSong = (ImageView) layout.findViewById(R.id.imvSong);
            txvSongTitle = (TextView) layout.findViewById(R.id.adap_txvSongtitle);
            txvSongInfo = (TextView) layout.findViewById(R.id.txvSongInfo);
        }
    }
}

Thanks!

the_dani
  • 2,466
  • 2
  • 20
  • 46

1 Answers1

0

the problem in your code would be the commented line :

        //holder.imvSong.setImageResource(R.drawable.standardartwork);

to handle this you have 2 solutions:

1) if u have limited small amount of known images, you can to create bitmaps/drawables once when initializing then you will only need to reference those.

2) create a bitmap cache, smart way to decode bitmaps along with reusable bitmap pool and pooling mechanism. This is not trivial and this what 3rd party libraries do for you. I would not suggest to implemented it yourself.

kalin
  • 3,546
  • 2
  • 25
  • 31