-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRecyclerViewActivity.java
175 lines (141 loc) · 5.95 KB
/
RecyclerViewActivity.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.lid.labelview;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.lid.lib.LabelImageView;
import java.util.ArrayList;
import java.util.List;
public class RecyclerViewActivity extends ActionBarActivity {
public class CategoryData {
public String image;
public String text;
public String label;
}
private List<CategoryData> datas;
private HomeAdapter mAdapter;
class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder>
{
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
RecyclerViewActivity.this).inflate(R.layout.list_view_item, parent,
false));
return holder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position)
{
holder.tv.setText(datas.get(position).text);
holder.labelImageView.setImageResource(Integer.parseInt(datas.get(position).image));
holder.labelImageView.setLabelText("LID " + position);
}
@Override
public int getItemCount()
{
return datas.size();
}
class MyViewHolder extends RecyclerView.ViewHolder
{
TextView tv;
LabelImageView labelImageView;
public MyViewHolder(View view)
{
super(view);
tv = (TextView) view.findViewById(R.id.text);
labelImageView = (LabelImageView) view.findViewById(R.id.image);
}
}
}
private RecyclerView mRecyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view);
datas = new ArrayList<>();
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mAdapter = new HomeAdapter());
getCategoryData();
getCategoryData();
getCategoryData();
mAdapter.notifyDataSetChanged();
}
private void getCategoryData() {
{
CategoryData item = new CategoryData();
item.text = "Following the founding of New China, the policy of cultural reawakening offered Kunqu Opera the chance to emerge from a long period of neglect.";
item.image = R.mipmap.k1 + "";
item.label = "MD";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "Kunqu Opera can trace its origins back to the Ming Dynasty about six hundred years ago, and a small town south of the Yangtze, called Kunshan.";
item.image = R.mipmap.k2 + "";
item.label = "FC";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "The popularity of Kunqu Opera historically has a lot to do with the support it received from the imperial court, from the time of Emperor Kangxi, onwards.";
item.image = R.mipmap.k3 + "";
item.label = "NFC";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "Perhaps the greatest masterpiece of Kunqu Opera is “The Peony Pavilion” written by Tang Xianzu in the early years of the 17th century.";
item.image = R.mipmap.k4 + "";
item.label = "GBA";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "Kunqu Opera is remarkable, if for nothing else, because of the long time it has been around. It continues to exert a strong appeal today.";
item.image = R.mipmap.k5 + "";
item.label = "PS";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "In the late Qing Dynasty, after five hundred years of development, Kunqu faced the greatest crisis in its existence.";
item.image = R.mipmap.k6 + "";
item.label = "XBOX";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "During the Qing Dynasty that followed, it became so popular that it was said to have an influence at every level of society, from the imperial court, down.";
item.image = R.mipmap.k7 + "";
item.label = "GB";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "The Qing Dynasty’s greatest playwrights, are Hong Sheng and Kong Shangren, who wrote, respectively, “The Palace of Eternal Youth” and “The Peach Blossom Fan”.";
item.image = R.mipmap.k8 + "";
item.label = "N64";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "Every period of history has its own fashions and tastes in clothing, music, etc. During the Ming Dynasty, it was fashionable among the intelligentsia to enjoy Kunqu Opera.";
item.image = R.mipmap.k9 + "";
item.label = "PSP";
datas.add(item);
}
{
CategoryData item = new CategoryData();
item.text = "Kunqu Opera can trace its origins back to the late Ming Dynasty and a small town south of the Yangtze, called Kunshan.";
item.image = R.mipmap.k10 + "";
item.label = "NDS";
datas.add(item);
}
}
}