1. MainActivity's XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:androaa">/apk/res/android"
xmlns:app="/apk/res-auto"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<
android:
android:layout_width="match_parent"
android:layout_height="wrap_content">
</>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#fff"
android:text="Sales"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#fff"
android:text="Sales"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#fff"
android:text="Sales"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#fff"
android:text="Sales"
/>
</LinearLayout>
<
android:
android:layout_width="match_parent"
android:layout_height="match_parent">
</>
</LinearLayout>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class MainActivity extends AppCompatActivity implements IView {
private IPersenterImpl iPersenter;
String path ="searchProducts";
private XRecyclerView xRecyclerView;
HeadView headView;
private BeanAdapter adapter;
private int page;
private boolean isLinear = true;
private Object message;
@Override
protected void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView(.activity_main);
iPersenter = new IPersenterImpl(this);
page = 1;
init();
//register
().register(this);
}
private void init() {
xRecyclerView = findViewById();
headView = findViewById();
//Click on the head to switch
(new () {
@Override
public void Click() {
List<> data = ();
changeLiGr();
(data);
}
});
//Change the header text and request again
(new () {
@Override
public void getName(String name) {
page = 1;
initData(name,page);
}
});
//Refresh load
(true);
(true);
changeLiGr();
(new () {
@Override
public void onRefresh() {
page = 1;
initData(message+"",page);
}
@Override
public void onLoadMore() {
initData(message+"",page);
}
});
}
//Change the state
private void changeLiGr(){
if (isLinear){
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
();
(layoutManager);
}else{
GridLayoutManager manager = new GridLayoutManager(this,2);
();
(manager);
}
adapter = new BeanAdapter(this,isLinear);
(adapter);
(new () {
@Override
public void click(int pid) {
Intent intent = new Intent(,);
("pid",pid);
startActivity(intent);
}
});
//Reverse status
isLinear = !isLinear;
}
//ask
private void initData(String name,int page) {
Map<String,String> pamars = new HashMap<>();
("keywords",name);
("page",page+"");
(path,pamars,);
}
//Get sticky events
@Subscribe(threadMode = ,sticky = true)
public void getName(EventBusBean eventBusBean){
if (() == 1) {
message = ();
initData(().toString(), page);
}
}
@Override
public void startRequestData(Object data) {
if (data instanceof GoodsBean){
GoodsBean bean = (GoodsBean) data;
if (page == 1){
(());
}else{
(());
}
page++;
();
();;
}
}
//Unbind
@Override
protected void onDestroy() {
();
();
().unregister(this);
}
}
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.