-
Notifications
You must be signed in to change notification settings - Fork 561
/
Copy pathRecyclerViewActivity.java
109 lines (93 loc) · 5.54 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
package zhou.demo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
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.zzhoujay.richtext.RichText;
/**
* Created by zhou on 16-6-17.
*/
public class RecyclerViewActivity extends AppCompatActivity {
private static final String[] testString1 = new String[]{
"<h3>Test1</h3><img src=\"http://h.hiphotos.baidu.com/image/h%3D200/sign=e72c850a09f3d7ca13f63876c21fbe3c/a2cc7cd98d1001e9460fd63bbd0e7bec54e797d7.jpg\" />",
"<h3>Test2</h3><img src=\"http://c.hiphotos.baidu.com/image/pic/item/f7246b600c3387448982f948540fd9f9d72aa0bb.jpg\" />",
"<h3>Test3</h3><img src=\"http://c.hiphotos.baidu.com/image/pic/item/267f9e2f070828382dcc0b20bd99a9014d08f1c5.jpg\" />",
"<h3>Test4</h3><img src=\"http://f.hiphotos.baidu.com/image/pic/item/32fa828ba61ea8d358824a0d950a304e251f5812.jpg\" />",
"<h3>Test5</h3><img src=\"http://f.hiphotos.baidu.com/image/pic/item/c2cec3fdfc039245831fa7498294a4c27c1e25c9.jpg\" />",
"<h3>Test6</h3><img src=\"http://e.hiphotos.baidu.com/image/pic/item/b999a9014c086e06613eab4b00087bf40ad1cb18.jpg\" />",
"<h3>Test7</h3><img src=\"http://a.hiphotos.baidu.com/image/pic/item/503d269759ee3d6d251670cb41166d224e4adeda.jpg\" />",
"<h3>Test8</h3><img src=\"http://f.hiphotos.baidu.com/image/pic/item/cb8065380cd791234275326baf345982b2b7801c.jpg\" />",
"<h3>Test9</h3><img src=\"http://a.hiphotos.baidu.com/image/pic/item/bba1cd11728b4710910b55c9c1cec3fdfc03238a.jpg\" />",
};
// private static final String[] testString1 = new String[]{
// "<h3>Test1</h3><p>hello</p>",
// "<h3>Test2</h3><p>hello</p>",
// "<h3>Test3</h3><p>hello</p>",
// "<h3>Test4</h3><p>hello</p>",
// "<h3>Test5</h3><p>hello</p>",
// "<h3>Test6</h3><p>hello</p>",
// "<h3>Test7</h3><p>hello</p>",
// "<h3>Test8</h3><p>hello</p>",
// "<h3>Test9</h3><p>hello</p>",
// };
private static final String[] testStringImage = {
"http://www.aikf.com/ask/resources/images/facialExpression/qq/1.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/2.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/3.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/4.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/5.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/6.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/7.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/8.gif",
"http://www.aikf.com/ask/resources/images/facialExpression/qq/9.gif",
};
private static final String[] testString = {
"<h3>Test1</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/1.gif\" />",
"<h3>Test2</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/2.gif\" />",
"<h3>Test3</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/3.gif\" />",
"<h3>Test4</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/4.gif\" />",
"<h3>Test5</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/5.gif\" />",
"<h3>Test6</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/6.gif\" />",
"<h3>Test7</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/7.gif\" />",
"<h3>Test8</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/8.gif\" />",
"<h3>Test9</h3><img src=\"http://www.aikf.com/ask/resources/images/facialExpression/qq/9.gif\" />",
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new Holder(LayoutInflater.from(RecyclerViewActivity.this).inflate(R.layout.item_list, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof Holder) {
Holder h = (Holder) holder;
RichText.from(testString1[position]).singleLoad(false).into(h.text);
}
}
@Override
public int getItemCount() {
return testString1.length;
}
class Holder extends RecyclerView.ViewHolder {
public TextView text;
public TextView id;
public Holder(View itemView) {
super(itemView);
text = (TextView) itemView.findViewById(R.id.text_item);
// id = (TextView) itemView.findViewById(R.id.text_id);
}
}
});
}
}