XMLファイルアダプタクラスを作成します - 主な活動に
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
: - アダプタで
myTagRecyclerView = (RecyclerView) view.findViewById(R.id.cardList);
RecyclerView.LayoutManager mLayoutManager = newLinearLayoutManager(this);
myTagRecyclerView.setLayoutManager(mLayoutManager);
myTagRecyclerView.setItemAnimator(new DefaultItemAnimator());
MyTagRecyclerViewAdapter adapterTagItemList = new MyTagRecyclerViewAdapter(this, dataList);
myTagRecyclerView.setAdapter(adapterTagItemList);
: -
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 com.tine.tine.R;
import java.util.List;
/**
* Created by Nishchal on 2/14/2017.
*/
public class TestRecycleView extends RecyclerView.Adapter<TestRecycleView.ViewHolder> {
private final Context mContext;
private List<TestModel> mTestModelList;
private String TAG = TestRecycleView.class.getSimpleName();
private OnItemClickListener onItemClickListener;
public TestRecycleView(Context mContext, List<TestModel> mTestModelList) {
this.mTestModelList = mTestModelList;
this.mContext = mContext;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recyle_view_item, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
TestModel mTestModel = mTestModelList.get(position);
//TODO Fill in your logic for binding the view.
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
@Override
public int getItemCount() {
if (mTestModelList == null) {
return 0;
}
return mTestModelList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public final TextView venuename_txtview = null;
public ViewHolder(View itemView) {
super(itemView);
// venuename_txtview = (TextView) itemView.findViewById(R.id.text);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
try {
if (onItemClickListener != null) {
onItemClickListener.onItemClick(v, getAdapterPosition());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
}
を
[RecyclerView Documentation](http://stackoverflow.com/documentation/android/169/recyclerview#t=201702140912313297647) –