Skip to content
This repository was archived by the owner on Nov 5, 2020. It is now read-only.

Commit 69c18b6

Browse files
committed
add CardView in recyclerview
1 parent 77741e4 commit 69c18b6

File tree

7 files changed

+64
-24
lines changed

7 files changed

+64
-24
lines changed

app/src/main/java/io/github/zhaoqi99/snnu_android/mNoticeRecyclerViewAdapter.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Intent;
44
import android.net.Uri;
5+
import android.support.v7.widget.CardView;
56
import android.support.v7.widget.RecyclerView;
67
import android.view.LayoutInflater;
78
import android.view.View;
@@ -10,6 +11,8 @@
1011

1112
import java.util.List;
1213

14+
import io.github.zhaoqi99.snnu_android.Model.NoticeMessage;
15+
1316
public class mNoticeRecyclerViewAdapter extends RecyclerView.Adapter<mNoticeRecyclerViewAdapter.ViewHolder>{
1417
private List<NoticeMessage> messageList;
1518

@@ -23,9 +26,11 @@ static class ViewHolder extends RecyclerView.ViewHolder{
2326
TextView Title;
2427
TextView Date;
2528
TextView Department;
29+
CardView CardView;
2630
public ViewHolder(View view)
2731
{
2832
super(view);
33+
CardView=(CardView)view.findViewById(R.id.card_view);
2934
Title = (TextView)view.findViewById(R.id.txt_Title);
3035
Date = (TextView)view.findViewById(R.id.txt_Date);
3136
Department = (TextView)view.findViewById(R.id.txt_Department);
@@ -48,7 +53,7 @@ public void onBindViewHolder(ViewHolder holder, int position) {
4853
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
4954
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.notice_recycler_layout,parent,false);
5055
final ViewHolder holder = new ViewHolder(view);
51-
holder.Title.setOnClickListener(new View.OnClickListener() {
56+
holder.CardView.setOnClickListener(new View.OnClickListener() {
5257
@Override
5358
public void onClick(View v) {
5459
int position=holder.getAdapterPosition();
@@ -60,6 +65,18 @@ public void onClick(View v) {
6065
v.getContext().startActivity(intent);
6166
}
6267
});
68+
// holder.Title.setOnClickListener(new View.OnClickListener() {
69+
// @Override
70+
// public void onClick(View v) {
71+
// int position=holder.getAdapterPosition();
72+
// String url=messageList.get(position).GetLink();
73+
// Uri uri=Uri.parse(url);
74+
// Intent intent=new Intent();
75+
// intent.setAction(Intent.ACTION_VIEW);
76+
// intent.setData(uri);
77+
// v.getContext().startActivity(intent);
78+
// }
79+
// });
6380
return holder;
6481
}
6582
}
Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
4-
android:layout_height="80dp">
5+
android:layout_height="wrap_content"
6+
android:padding="5dp">
57

6-
<TextView
8+
<android.support.v7.widget.CardView
9+
android:id="@+id/card_view"
710
android:layout_width="match_parent"
811
android:layout_height="wrap_content"
9-
android:id="@+id/txt_Title"
10-
android:layout_alignParentTop="true"
11-
android:layout_alignParentStart="true"
12-
android:layout_marginTop="14dp"
13-
android:textSize="18sp"
14-
android:textColor="#000"/>
12+
android:clickable="true"
13+
android:foreground="?android:attr/selectableItemBackground"
14+
app:cardCornerRadius="8dp"
15+
app:cardElevation="8dp">
1516

16-
<TextView
17-
android:layout_width="200dp"
18-
android:layout_height="wrap_content"
19-
android:id="@+id/txt_Department"
20-
android:layout_marginBottom="12dp"
21-
android:layout_alignParentBottom="true"
22-
android:layout_alignParentStart="true"
23-
android:layout_marginStart="13dp" />
17+
<LinearLayout
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:orientation="vertical">
2421

25-
<TextView
26-
android:layout_width="150dp"
27-
android:layout_height="wrap_content"
28-
android:id="@+id/txt_Date"
29-
android:layout_alignBaseline="@+id/txt_Department"
30-
android:layout_alignBottom="@+id/txt_Department"
31-
android:layout_toEndOf="@+id/txt_Department" />
22+
<TextView
23+
android:id="@+id/txt_Title"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:textColor="#000"
27+
android:textSize="18sp" />
28+
29+
<LinearLayout
30+
android:layout_width="match_parent"
31+
android:layout_height="match_parent"
32+
android:orientation="horizontal">
33+
34+
<TextView
35+
android:id="@+id/txt_Department"
36+
android:layout_width="wrap_content"
37+
android:layout_height="match_parent"
38+
android:layout_marginLeft="8dp"
39+
android:text="xx" />
40+
<!--用于两端对齐-->
41+
<TextView
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:layout_weight="1" />
45+
46+
<TextView
47+
android:id="@+id/txt_Date"
48+
android:layout_width="wrap_content"
49+
android:layout_height="match_parent"
50+
android:text="xx" />
51+
</LinearLayout>
52+
</LinearLayout>
53+
</android.support.v7.widget.CardView>
3254
</RelativeLayout>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
<color name="red_background">#FF0000</color>
77
<color name="colorDrawerHeader">#3BCAB7</color>
88
<color name="colorDrawerBackground">#FFFFFF</color>
9+
<color name="colorNews">#FAFAFA</color>
910
</resources>

0 commit comments

Comments
 (0)