-
Notifications
You must be signed in to change notification settings - Fork 523
Expand file tree
/
Copy pathRecyclerViewExample.java
More file actions
93 lines (72 loc) · 3.67 KB
/
RecyclerViewExample.java
File metadata and controls
93 lines (72 loc) · 3.67 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package uk.co.deanwild.materialshowcaseviewsample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewTreeObserver;
import java.util.ArrayList;
import java.util.Objects;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseSequence;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
import uk.co.deanwild.materialshowcaseview.ShowcaseConfig;
public class RecyclerViewExample extends AppCompatActivity {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view_example);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("How to show on recycler view?");
arrayList.add("How to show on recycler view?");
arrayList.add("How to show on recycler view?");
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new RecyclerViewAdapter(this, arrayList));
checkedFillAllData();
}
private void checkedFillAllData() {
// It is used to run all the data in the list after it is filled.
// Otherwise, it will not work because it cannot find the first line in direct use, and it will give an empty object error.
recyclerView.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// I want to get the first line
RecyclerViewAdapter.MyViewHolder myViewHolder = (RecyclerViewAdapter.MyViewHolder) recyclerView.findViewHolderForAdapterPosition(0);
// I catch ImageView object of the first line
View targetImageView = myViewHolder.imageView;
// I catch RelativeLayout object of the first line
View targetRelativeLayout = myViewHolder.relativeLayout;
// We show the objects we obtain sequentially
createShowCaseView(targetImageView, targetRelativeLayout);
// If you don't do it, it will always create
// Minimum Sdk Version should be 16
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
private void createShowCaseView(View imageView, View relativeLayout) {
ShowcaseConfig config = new ShowcaseConfig();
MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this);
sequence.setConfig(config);
sequence.addSequenceItem(new MaterialShowcaseView.Builder(this)
.setTarget(relativeLayout)
.withRectangleShape()
.setContentText("This shows the whole line")
.setDismissText("Next")
.setDismissOnTouch(true)
.build());
sequence.addSequenceItem(new MaterialShowcaseView.Builder(this)
.setTarget(imageView)
.withCircleShape()
.setContentText("OK")
.setDismissText("This shows the imageView object in the entire row")
.setDismissOnTouch(true)
.build());
sequence.start();
}
}