use of xyz.zpayh.adapter.BaseViewHolder in project SherlockAdapter by EvilBT.
the class MainActivity method initView.
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mRecyclerView = (RecyclerView) findViewById(R.id.list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
final BaseAdapter<String> adapter = new BaseAdapter<String>() {
@Override
public int getLayoutRes(int index) {
return R.layout.item_list;
}
@Override
public void convert(BaseViewHolder holder, String data, int index) {
holder.setText(R.id.tv_act_title, data);
}
@Override
public void bind(BaseViewHolder holder, int layoutRes) {
holder.setClickable(R.id.app_root, true);
}
};
adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull View view, int adapterPosition) {
String action = adapter.getData(adapterPosition);
Intent intent = new Intent();
intent.setAction(action);
startActivity(intent);
}
});
mRecyclerView.setAdapter(adapter);
String[] list = getResources().getStringArray(R.array.activity_title);
final List<String> data = new ArrayList<>(list.length);
for (String s : list) {
data.add(s);
}
adapter.setData(data);
}
Aggregations