5
public class QiuckAdapterSample extends JobBasicActivity { private RefreshAndLoadLayout mRefreshAndLoadLayout; private RecyclerView mRecyclerView; private SilentTask mDataLoaderTask; private Adapter adapter;
@Override
protected void onInitParams(Bundle bundle) {
}
@Override
protected void setupViews(Bundle savedInstanceState) {
setContentView(R.layout.base_refresh_layout);
mRefreshAndLoadLayout = (RefreshAndLoadLayout) findViewById(R.id.refresh_load_layout);
mRefreshAndLoadLayout.initLoadingView(true);
mRefreshAndLoadLayout.setPullUpEnable(false);
mRefreshAndLoadLayout.setOnRefreshListener(new RefreshAndLoadLayout.OnRefreshListener() {
@Override
public void onPullDownToRefresh() {
startLoading();
}
});
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new Adapter(R.layout.resume_viewed_item,new DataItemResult().getDataList());
adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
@Override
public void onLoadMoreRequested() {
Log.e("tag","onLoadMoreRequested");
startLoading();
}
});
adapter.setEnableLoadMore(true);
adapter.bindToRecyclerView(mRecyclerView);
adapter.disableLoadMoreIfNotFullPage();
startLoading();
}
public class Adapter extends BaseQuickAdapter<DataItemDetail,BaseViewHolder>{
public Adapter(int layoutResId, List<DataItemDetail> data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, DataItemDetail item) {
helper.setText(R.id.company_name,item.getString("coname"));
helper.setImageResource(R.id.tag,item.getBoolean("ismysend") ? R.drawable.resume_viewed_hr_check : R.drawable.resume_viewed_hr_search);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(item.getString("cotypename"))
.append(getString(R.string.my51job_resumeviewed_item_divide))
.append(item.getString("cosizename"))
.append(getString(R.string.my51job_resumeviewed_item_divide))
.append(item.getString("indtypename"));
helper.setText(R.id.company_property,stringBuilder.toString());
helper.setText(R.id.viewed_resume_time,item.getString("viewtime"));
}
}
public void startLoading(){
mDataLoaderTask = new SilentTask() {
@Override
protected DataItemResult doInBackground(String... params) {
return 访问接口;
}
@Override
protected void onTaskFinished(DataItemResult result) {
// 默认给十条数据,可以满屏。
List<DataItemDetail> list = new ArrayList<>();
for (int i = 0; i < 5;i++){
list.addAll(result.getDataList());
}
adapter.addData(list);
mRefreshAndLoadLayout.stopRefresh();
adapter.loadMoreComplete();
}
};
mDataLoaderTask.executeOnPool();
}
}