Back to project page androidui.
The source code is released under:
MIT License
If you think the Android project androidui listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package course.examples.UI.RecyclerView; /* www .j ava 2s. c o m*/ import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import java.util.List; public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder>{ private final List<String> mNames; private final Context mContext; private int mRowLayout; public MyRecyclerViewAdapter(List<String> names, int rowLayout, Context context) { mNames = names; mContext = context; mRowLayout = rowLayout; } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(mRowLayout, viewGroup, false); return new MyRecyclerViewAdapter.ViewHolder(v); } @Override public void onBindViewHolder(ViewHolder viewHolder, int i) { viewHolder.mName.setText(mNames.get(i)); } public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public TextView mName; public ViewHolder(View itemView) { super(itemView); mName = (TextView) itemView.findViewById(R.id.text); itemView.setOnClickListener(this); } @Override public void onClick(View view) { // Display a Toast message indicting the selected item Toast.makeText(view.getContext(), mName.getText(), Toast.LENGTH_SHORT).show(); } } @Override public int getItemCount() { return (null == mNames) ? 0 : mNames.size(); } }