Skip to content

Commit a1a174c

Browse files
committed
demo
1 parent 7f46200 commit a1a174c

File tree

8 files changed

+56
-48
lines changed

8 files changed

+56
-48
lines changed

app/src/main/java/com/cjj/loadmorervdemo/DemoRvAdapter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
import android.view.LayoutInflater;
66
import android.view.View;
77
import android.view.ViewGroup;
8+
import android.widget.ImageView;
89
import android.widget.TextView;
910

11+
import java.net.Inet4Address;
1012
import java.util.List;
1113

1214
public class DemoRvAdapter extends RecyclerView.Adapter<DemoRvAdapter.MyViewHolder> {
1315

1416
private Context mContext;
15-
private List<String> mDatas;
16-
public DemoRvAdapter(Context context, List<String> mDatas){
17+
private List<Integer> mDatas;
18+
public DemoRvAdapter(Context context, List<Integer> mDatas){
1719
mContext = context;
1820
this.mDatas = mDatas;
1921
}
@@ -30,7 +32,7 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
3032
@Override
3133
public void onBindViewHolder(MyViewHolder holder, int position)
3234
{
33-
holder.tv.setText(mDatas.get(position));
35+
holder.mImageViewv.setImageResource(mDatas.get(position));
3436
}
3537

3638
@Override
@@ -42,12 +44,12 @@ public int getItemCount()
4244
class MyViewHolder extends RecyclerView.ViewHolder
4345
{
4446

45-
TextView tv;
47+
ImageView mImageViewv;
4648

4749
public MyViewHolder(View view)
4850
{
4951
super(view);
50-
tv = (TextView) view.findViewById(R.id.id_num);
52+
mImageViewv = (ImageView) view.findViewById(R.id.iv_image);
5153
}
5254
}
5355
}
Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.cjj.loadmorervdemo;
22

33
import android.os.Bundle;
4-
import android.support.design.widget.FloatingActionButton;
5-
import android.support.design.widget.Snackbar;
4+
import android.os.Handler;
5+
import android.support.v4.widget.SwipeRefreshLayout;
66
import android.support.v7.app.AppCompatActivity;
77
import android.support.v7.widget.Toolbar;
88
import android.view.Menu;
99
import android.view.MenuItem;
10-
import android.view.View;
1110

11+
import com.cjj.MaterialFootItem;
1212
import com.cjj.OnLoadMoreListener;
1313
import com.cjj.RecyclerViewWithFooter;
1414

@@ -18,7 +18,7 @@
1818

1919
public class MainActivity extends AppCompatActivity {
2020

21-
private List<String> mDatas;
21+
private List<Integer> mDatas;
2222
private RecyclerViewWithFooter mRecyclerViewWithFooter;
2323

2424
@Override
@@ -28,49 +28,56 @@ protected void onCreate(Bundle savedInstanceState) {
2828
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
2929
setSupportActionBar(toolbar);
3030

31-
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
32-
fab.setOnClickListener(new View.OnClickListener() {
31+
final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
32+
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_red_light,android.R.color.holo_blue_light,android.R.color.holo_green_light);
33+
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
3334
@Override
34-
public void onClick(View view) {
35-
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
36-
.setAction("Action", null).show();
35+
public void onRefresh() {
36+
new Handler().postDelayed(new Runnable() {
37+
@Override
38+
public void run() {
39+
mDatas.clear();
40+
addData();
41+
swipeRefreshLayout.setRefreshing(false);
42+
}
43+
},3000);
3744
}
3845
});
3946

40-
4147
initData();
48+
4249
mRecyclerViewWithFooter = (RecyclerViewWithFooter) this.findViewById(R.id.rv_load_more);
4350
mRecyclerViewWithFooter.setAdapter(new DemoRvAdapter(this, mDatas));
51+
// mRecyclerViewWithFooter.setFootItem(new DefaultFootItem());//默认是这种
52+
mRecyclerViewWithFooter.setFootItem(new MaterialFootItem());//material 风格
53+
// mRecyclerViewWithFooter.setFootItem(new CustomFootItem());//自定义
4454
mRecyclerViewWithFooter.setOnLoadMoreListener(new OnLoadMoreListener() {
4555
@Override
4656
public void onLoadMore() {
4757

4858
mRecyclerViewWithFooter.postDelayed(new Runnable() {
4959
@Override
5060
public void run() {
51-
addData(1);
61+
addData();
5262
}
53-
}, 3000);
63+
}, 2000);
5464
}
5565
});
56-
57-
58-
59-
6066
}
6167

6268
protected void initData() {
63-
mDatas = new ArrayList<String>();
64-
for (int i = 0; i < 50; i++) {
65-
mDatas.add("" + i);
66-
}
69+
mDatas = new ArrayList<>();
70+
mDatas.add(R.mipmap.cat1);
71+
mDatas.add(R.mipmap.cat2);
72+
mDatas.add(R.mipmap.cat3);
73+
mDatas.add(R.mipmap.cjj);
6774
}
6875

69-
protected void addData(int k) {
70-
for (int i = k; i < k + 50; i++) {
71-
mDatas.add("" + i);
72-
}
73-
76+
protected void addData() {
77+
mDatas.add(R.mipmap.cat1);
78+
mDatas.add(R.mipmap.cat2);
79+
mDatas.add(R.mipmap.cat3);
80+
mDatas.add(R.mipmap.cjj);
7481
mRecyclerViewWithFooter.getAdapter().notifyDataSetChanged();
7582

7683
}
@@ -92,7 +99,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
9299
//noinspection SimplifiableIfStatement
93100
if (id == R.id.addMoreAction) {
94101
mRecyclerViewWithFooter.setLoad();
95-
addData(1);
102+
addData();
96103
return true;
97104
}
98105
if (id == R.id.endAction) {
@@ -108,6 +115,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
108115
return true;
109116
}
110117

118+
111119
return super.onOptionsItemSelected(item);
112120
}
113121
}

app/src/main/res/layout/activity_main.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,5 @@
2525

2626
<include layout="@layout/content_main"/>
2727

28-
<android.support.design.widget.FloatingActionButton
29-
android:id="@+id/fab"
30-
android:layout_width="wrap_content"
31-
android:layout_height="wrap_content"
32-
android:layout_gravity="bottom|end"
33-
android:layout_margin="@dimen/fab_margin"
34-
android:src="@android:drawable/ic_dialog_email"/>
3528

3629
</android.support.design.widget.CoordinatorLayout>

app/src/main/res/layout/content_main.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
tools:showIn="@layout/activity_main">
1111

1212

13-
14-
<com.cjj.RecyclerViewWithFooter
15-
android:id="@+id/rv_load_more"
13+
<android.support.v4.widget.SwipeRefreshLayout
14+
android:id="@+id/swipe"
1615
android:layout_width="match_parent"
1716
android:layout_height="match_parent">
1817

19-
</com.cjj.RecyclerViewWithFooter>
18+
<com.cjj.RecyclerViewWithFooter
19+
android:id="@+id/rv_load_more"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent">
22+
</com.cjj.RecyclerViewWithFooter>
2023

24+
</android.support.v4.widget.SwipeRefreshLayout>
2125
</RelativeLayout>

app/src/main/res/menu/menu_main.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
android:orderInCategory="100"
1818
android:title="empty"
1919
app:showAsAction="never"/>
20+
21+
22+
2023
</menu>

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#3F51B5</color>
3+
<color name="colorPrimary">@android:color/holo_red_light</color>
44
<color name="colorPrimaryDark">#303F9F</color>
55
<color name="colorAccent">#FF4081</color>
66
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
2-
<string name="app_name">LoadMoreRvDemo</string>
2+
<string name="app_name">RVWithFooter</string>
33
<string name="action_settings">Settings</string>
44
<string name="loading">加载中...</string>
55
<string name="no_more">end</string>

library/src/main/java/com/cjj/FootItem.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
*/
99
public abstract class FootItem {
1010

11-
12-
1311
public CharSequence loadText;
1412
public CharSequence endText;
1513

16-
abstract View onCreateView(ViewGroup parent);
14+
public abstract View onCreateView(ViewGroup parent);
1715

18-
abstract void onBindData(View view, int state);
16+
public abstract void onBindData(View view, int state);
1917

2018
}

0 commit comments

Comments
 (0)