依赖
implementation (‘com.jcodecraeer:xrecyclerview:1.5.9’){
exclude group: ‘com.android.support’
}
public class MainActivity extends AppCompatActivity implements ViewCar,AdapterList.AdapterListener{
private XRecyclerView xRecyclerViewList;
private RecyclerView recyclerViewShow;
private PresentCar presentCar;
private AdapterList adapterList;
private AdapterShow adapterShow;
private int num=3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xRecyclerViewList = findViewById(R.id.recyclerViewList);
xRecyclerViewList.setPullRefreshEnabled(true);
xRecyclerViewList.setLoadingMoreEnabled(true);
recyclerViewShow = findViewById(R.id.recyclerViewShow);
presentCar = new PresentCar(this);
presentCar.getList();
presentCar.getShow(num);
}
@Override
public void onSuccess(List<BeanList.DataBean> list) {
xRecyclerViewList.setLayoutManager(new LinearLayoutManager(this));
adapterList = new AdapterList(list);
xRecyclerViewList.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"成功",Toast.LENGTH_SHORT).show();
}
},2000);
xRecyclerViewList.refreshComplete();
}
@Override
public void onLoadMore() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"成功",Toast.LENGTH_SHORT).show();
}
},2000);
xRecyclerViewList.loadMoreComplete();
}
});
xRecyclerViewList.setAdapter(adapterList);
adapterList.setListener(this);
}
@Override
public void onFailed(String msg) {
Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccessShow(List<BeanShow.DataBean> list) {
recyclerViewShow.setLayoutManager(new LinearLayoutManager(this));
adapterShow = new AdapterShow(list);
recyclerViewShow.setAdapter(adapterShow);
}
@Override
public void onFailedShow(String error) {
Toast.makeText(MainActivity.this,error,Toast.LENGTH_SHORT).show();
}
@Override
public void OnItemClick(int cid) {
num=cid;
presentCar.getShow(num);
}
}