Skip to content

Commit 10ab032

Browse files
committed
loadDataOffset Algorithm changed. '1' TextView in layout removed
1 parent d26e9be commit 10ab032

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

app/src/main/java/com/aroliant/endlessrecyclerview/EndlessRecyclerViewAdapter.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class EndlessRecyclerViewAdapter extends RecyclerView.Adapter<EndlessRecy
2323

2424
Context context;
2525
ArrayList<String> names = new ArrayList<String>();
26+
ArrayList<Integer> count = new ArrayList<Integer>();
27+
2628

2729
private int visibleThreshold = 5;
2830
private int lastVisibleItem, totalItemCount;
@@ -49,9 +51,11 @@ public ViewHolder(View v) {
4951

5052
public EndlessRecyclerViewAdapter(Context context,
5153
RecyclerView recyclerView,
52-
ArrayList<String> names) {
54+
ArrayList<String> names,
55+
ArrayList<Integer> count) {
5356
this.context = context;
5457
this.names = names;
58+
this.count = count;
5559

5660
if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
5761

@@ -108,7 +112,7 @@ public EndlessRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent
108112
public void onBindViewHolder(final ViewHolder holder, int position) {
109113

110114
holder.mTextViewName.setText(names.get(position));
111-
holder.mTextViewCount.setText(String.valueOf(position));
115+
holder.mTextViewCount.setText(count.get(position) + "");
112116

113117
}
114118

app/src/main/java/com/aroliant/endlessrecyclerview/MainActivity.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
public class MainActivity extends AppCompatActivity {
1313

1414
ArrayList<String> names = new ArrayList<String>();
15+
ArrayList<Integer> count = new ArrayList<Integer>();
1516

1617
int offset = 0;
1718

@@ -41,7 +42,8 @@ protected void onCreate(Bundle savedInstanceState) {
4142

4243
mAdapter = new EndlessRecyclerViewAdapter(this,
4344
recyclerView,
44-
names);
45+
names,
46+
count);
4547

4648
recyclerView.setAdapter(mAdapter);
4749

@@ -54,8 +56,7 @@ public void onLoadMore() {
5456
@Override
5557
public void run() {
5658

57-
loadDataOffset(offset);
58-
offset++;
59+
loadDataOffset();
5960

6061
}
6162
}, 10);
@@ -65,24 +66,19 @@ public void run() {
6566
}
6667
});
6768

68-
loadDataOffset(offset);
69+
loadDataOffset();
6970

7071

7172
}
7273

73-
void loadDataOffset(int _offset){
74+
void loadDataOffset(){
7475

76+
int _offset = offset;
7577

76-
int i = _offset * 10;
77-
78-
Log.d("...",i + "");
79-
80-
if(i == 0){
81-
i = 0;
82-
}
83-
84-
for (int j = i ; j < (i + 10) ; j++ ){
78+
for (int j = _offset ; j < (_offset + 10) ; j++ ){
8579
names.add("Name " + j);
80+
count.add(j);
81+
offset++;
8682
Log.d("...", j + "");
8783
}
8884

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
android:id="@+id/recycler_view"
1111
android:scrollbars="none"
1212
android:layout_width="match_parent"
13-
android:layout_weight="1"
1413
android:layout_height="match_parent"/>
1514

1615

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<TextView
3030
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
32-
android:text="1"
3332
android:padding="5dp"
3433
android:textColor="#FFF"
3534
android:id="@+id/count"
@@ -43,18 +42,10 @@
4342
android:layout_height="wrap_content"
4443
android:padding="5dp"
4544
android:layout_marginLeft="20dp"
46-
android:text="Sample"
45+
android:text=""
4746
android:textColor="#ffffff" />
4847

4948

50-
<TextView
51-
android:layout_width="wrap_content"
52-
android:layout_height="wrap_content"
53-
android:text="1"
54-
android:padding="5dp"
55-
android:textColor="#FFF"
56-
android:id="@+id/lb_points"
57-
/>
5849

5950
</RelativeLayout>
6051

0 commit comments

Comments
 (0)