xbanner+RecyclerView的Activity

public class MainActivity extends AppCompatActivity implements Contract.Iview {

private Presenter presenter;
private  String url="http://172.17.8.100/small/commodity/v1/commodityList";
private  String xurl="http://172.17.8.100/small/commodity/v1/bannerShow";
private RecyclerView recycler_view;
private RecyBean bean;
private XbannerBean xbannerBean;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    presenter = new Presenter();
    presenter.attch(this);
    presenter.show(url);
    presenter.showXbanner(xurl);
    //初始化控件
    initView();
}

private void initView() {
    recycler_view = findViewById(R.id.recycler_view);
    //布局管理器
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recycler_view.setLayoutManager(linearLayoutManager);
}

//列表
@Override
public void getRequest(String data) {
Gson gson = new Gson();
bean = gson.fromJson(data, RecyBean.class);
ShowAdapter showAdapter = new ShowAdapter(this, bean, xbannerBean);
recycler_view.setAdapter(showAdapter);
}
//轮播
@Override
public void getXbannerRequest(String data) {
Gson gson = new Gson();
xbannerBean = gson.fromJson(data, XbannerBean.class);
ShowAdapter showAdapter = new ShowAdapter(this, bean, xbannerBean);
recycler_view.setAdapter(showAdapter);

}

@Override
protected void onDestroy() {
    super.onDestroy();
    presenter.detch();
}

}

你可能感兴趣的:(电商__小1)