第一步定义布局 定义两个布局 RecyclerView
展示页面首页
package com.bawei.moni;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.bawei.moni.adapter.ShowAdapter;
import com.bawei.moni.adapter.ThreeAdapter;
import com.bawei.moni.adapter.TwoAdapter;
import com.bawei.moni.api.Api;
import com.bawei.moni.bean.JsonBean;
import com.bawei.moni.bean.ListBean;
import com.bawei.moni.bean.TwoBean;
import com.bawei.moni.iview.Iview;
import com.bawei.moni.presenter.Presenter;
import com.bawei.moni.search.SearchView;
import com.google.gson.Gson;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.List;
public class MainActivity extends AppCompatActivity implements Iview {
private SearchView searchView;
private XRecyclerView xRecyclerView;
private ImageView imageView;
private ImageView imageView_dianji;
private RecyclerView popWindow;
private PopupWindow popupWindow;
private TextView ttt;
private Presenter presenter;
private RecyclerView rlv_first;
private LayoutInflater inflate;
private String s="1001002";
private String t="1001004002";
private RecyclerView rlv_two;
private ShowAdapter showAdapter;
private PopupWindow popupWindow2;
private RecyclerView three_rly;
private TwoAdapter twoAdapter;
private PopupWindow window;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化
searchView = findViewById(R.id.main_search);
imageView_dianji = findViewById(R.id.sou_iamge);
//初始化p层
presenter = new Presenter();
presenter.attchView(this);
presenter.getDataThree(Api.Url_three+"?categoryId="+t+"&page="+1+"&count="+5,MainActivity.this);
//图片点击
imageView_dianji.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.getData(Api.Url,MainActivity.this);
}
});
}
//一级列表
@Override
public void getData(String data) {
/*
* 找布局
* */
**假如说是fragment 页面 这里必须写getActivity方法**
inflate = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View view1 = inflate.inflate(R.layout.pupowindow_layout, null);
rlv_first = view1.findViewById(R.id.pop_rx);
Gson gson=new Gson();
JsonBean jsonBean = gson.fromJson(data, JsonBean.class);
final List list = jsonBean.getResult();
LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
showAdapter = new ShowAdapter(list, MainActivity.this);
rlv_first.setLayoutManager(layoutManager);
rlv_first.setAdapter(showAdapter);
showAdapter.setOnclink(new ShowAdapter.OneOnclink() {
@Override
public void onClink(int pition) {
String id = list.get(pition).getId();
presenter.getDataTwo(Api.Url_two+"?firstCategoryId="+id,MainActivity.this);
}
});
/*
* 創建popwindow
* */
popupWindow = new PopupWindow(view1, ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT
);
//设置
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
//设置颜色
ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
popupWindow.setBackgroundDrawable(colorDrawable);
popupWindow.showAsDropDown(imageView_dianji);
}
//二级列表
@Override
public void getDataTwo(String data) {
//找布局
View inflate = this.inflate.inflate(R.layout.pop_second, null);
rlv_two = inflate.findViewById(R.id.pop_rx2);
Gson gson=new Gson();
TwoBean twoBean = gson.fromJson(data, TwoBean.class);
final List result = twoBean.getResult();
LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
twoAdapter = new TwoAdapter(result, MainActivity.this);
rlv_two.setLayoutManager(layoutManager);
rlv_two.setAdapter(twoAdapter);
//点击
twoAdapter.setTwoOnclink(new TwoAdapter.TwoOnclink() {
@Override
public void onClink(int potion) {
String id = result.get(potion).getId();
Log.e("qqq",id);
presenter.getDataThree(Api.Url_three+"?categoryId="+id+"&page="+1+"&count="+5,MainActivity.this);
}
});
popupWindow2 = new PopupWindow(inflate, ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT
);
//设置
popupWindow2.setOutsideTouchable(true);
popupWindow2.setFocusable(true);
//设置颜色
ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
popupWindow2.setBackgroundDrawable(colorDrawable);
popupWindow2.showAsDropDown(imageView_dianji,50,50);
}
//三级列表
@Override
public void getDataThree(String data) {
//找布局
Log.e("qqq",data.toString());
View inflate = this.inflate.inflate(R.layout.pop_three, null);
three_rly = inflate.findViewById(R.id.three_rly);
Gson gson=new Gson();
ListBean listBean = gson.fromJson(data, ListBean.class);
List list = listBean.getResult();
Log.e("www",list.toString());
ThreeAdapter threeAdapter=new ThreeAdapter(list,MainActivity.this);
GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 2);
three_rly.setLayoutManager(gridLayoutManager);
three_rly.setAdapter(threeAdapter);
window = new PopupWindow(inflate, ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT
);
//设置
window.setOutsideTouchable(true);
window.setFocusable(true);
//设置颜色
ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
window.setBackgroundDrawable(colorDrawable);
window.showAsDropDown(imageView_dianji,90,90);
}
}