Android Open Source - FloatingActionButton Recycler View Adapter






From Project

Back to project page FloatingActionButton.

License

The source code is released under:

MIT License

If you think the Android project FloatingActionButton listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.melnykov.fab.sample;
/* www.j a v  a 2  s.  c  o m*/
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
    private final Context mContext;
    private final String[] mDataset;

    public RecyclerViewAdapter(Context context, String[] dataset) {
        mContext = context;
        mDataset = dataset;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        String[] values = mDataset[position].split(",");
        String countryName = values[0];
        int flagResId = mContext.getResources().getIdentifier(values[1], "drawable", mContext.getPackageName());
        viewHolder.mTextView.setText(countryName);
        viewHolder.mTextView.setCompoundDrawablesWithIntrinsicBounds(flagResId, 0, 0, 0);
    }

    @Override
    public int getItemCount() {
        return mDataset.length;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;

        public ViewHolder(TextView v) {
            super(v);
            mTextView = v;
        }
    }
}




Java Source Code List

com.melnykov.fab.AbsListViewScrollDetector.java
com.melnykov.fab.FloatingActionButton.java
com.melnykov.fab.ObservableScrollView.java
com.melnykov.fab.RecyclerViewScrollDetector.java
com.melnykov.fab.ScrollDirectionListener.java
com.melnykov.fab.ScrollViewScrollDetector.java
com.melnykov.fab.sample.DividerItemDecoration.java
com.melnykov.fab.sample.ListViewAdapter.java
com.melnykov.fab.sample.MainActivity.java
com.melnykov.fab.sample.RecyclerViewAdapter.java