use of com.hpu.baserecyclerviewadapter.sample.multi.FirstItem in project BaseRecyclerViewAdapter by donghan0912.
the class MultiTypeFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
refreshLayout.setEnabled(false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
list = new ArrayList<>();
for (int i = 0; i < 6; i++) {
list.add(new FirstItem("第" + i + "条数据"));
list.add(new SecondItem("第" + i + "条数据"));
if (i == 0) {
list.add(new ThirdItem(R.drawable.luoluo_1));
} else if (i == 1) {
list.add(new ThirdItem(R.drawable.luoluo_2));
} else if (i == 2) {
list.add(new ThirdItem(R.drawable.luoluo_3));
} else if (i == 3) {
list.add(new ThirdItem(R.drawable.luoluo_4));
} else if (i == 4) {
list.add(new ThirdItem(R.drawable.luoluo_5));
} else if (i == 5) {
list.add(new ThirdItem(R.drawable.luoluo_6));
}
}
final BaseRecyclerViewAdapter baseRecyclerViewAdapter = new BaseRecyclerViewAdapter();
recyclerView.setAdapter(baseRecyclerViewAdapter);
baseRecyclerViewAdapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Toast.makeText(getContext(), position + "", Toast.LENGTH_SHORT).show();
}
});
baseRecyclerViewAdapter.setOnItemLongClickListener(new BaseRecyclerViewAdapter.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(View view, int position) {
Toast.makeText(getContext(), position + "", Toast.LENGTH_SHORT).show();
return false;
}
});
baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_loading));
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_error) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
holder.setOnClickListener(R.id.retry, new View.OnClickListener() {
@Override
public void onClick(View v) {
baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_loading));
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
baseRecyclerViewAdapter.setData(list);
}
}, 3000);
}
});
}
});
}
}, 3000);
}
Aggregations