parent
5aaf699f71
commit
5be83fe731
@ -0,0 +1,78 @@ |
||||
package com.community.pocket.data.adapter; |
||||
|
||||
import android.content.Context; |
||||
import android.text.format.DateFormat; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
import android.widget.TextView; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.data.model.Notice; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 公告内容 |
||||
*/ |
||||
public class NoticeAdpter extends RecyclerView.Adapter<NoticeAdpter.PagerViewHolder> { |
||||
|
||||
private List<Notice> noticeList; |
||||
|
||||
public NoticeAdpter(List<Notice> noticeList) { |
||||
this.noticeList = noticeList; |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public PagerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.forum_notice, parent, false); |
||||
return new PagerViewHolder(itemView); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull PagerViewHolder holder, int position) { |
||||
Notice notice = noticeList.get(position); |
||||
//设置数据源
|
||||
holder.title.setText(notice.getTitle()); |
||||
holder.content.setText(notice.getContent()); |
||||
Context context = holder.author.getContext(); |
||||
Date date = new Date(); |
||||
date.setTime(notice.getTime()); |
||||
holder.author.setText(context.getString(R.string.notice_author, notice.getAuthor())); |
||||
holder.time.setText(context.getString(R.string.notice_time, DateFormat.format(context.getString(R.string.dateformat), date))); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return noticeList.size(); |
||||
} |
||||
|
||||
// ViewHolder需要继承RecycleView.ViewHolder
|
||||
static class PagerViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
//公告标题
|
||||
private TextView title; |
||||
//公告内容
|
||||
private TextView content; |
||||
//公告管理员
|
||||
private TextView author; |
||||
//公告时间
|
||||
private TextView time; |
||||
|
||||
PagerViewHolder(@NonNull View itemView) { |
||||
super(itemView); |
||||
//初始化组件
|
||||
title = itemView.findViewById(R.id.notice_title); |
||||
content = itemView.findViewById(R.id.notice_content); |
||||
author = itemView.findViewById(R.id.notice_author); |
||||
time = itemView.findViewById(R.id.notice_time); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,47 @@ |
||||
package com.community.pocket.data.model; |
||||
|
||||
/** |
||||
* 公告信息 |
||||
*/ |
||||
public class Notice { |
||||
//公告标题
|
||||
private String title; |
||||
//公告内容
|
||||
private String content; |
||||
//公告人
|
||||
private String author; |
||||
//公告时间
|
||||
private Long time; |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
|
||||
public void setTitle(String title) { |
||||
this.title = title; |
||||
} |
||||
|
||||
public String getContent() { |
||||
return content; |
||||
} |
||||
|
||||
public void setContent(String content) { |
||||
this.content = content; |
||||
} |
||||
|
||||
public String getAuthor() { |
||||
return author; |
||||
} |
||||
|
||||
public void setAuthor(String author) { |
||||
this.author = author; |
||||
} |
||||
|
||||
public Long getTime() { |
||||
return time; |
||||
} |
||||
|
||||
public void setTime(Long time) { |
||||
this.time = time; |
||||
} |
||||
} |
@ -0,0 +1,62 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<TextView |
||||
android:id="@+id/notice_title" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="center" |
||||
android:textSize="36sp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
<ScrollView |
||||
android:id="@+id/content" |
||||
android:layout_width="0dp" |
||||
android:layout_height="100dp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@id/notice_title"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<EditText |
||||
android:id="@+id/notice_content" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:ems="10" |
||||
android:enabled="false" |
||||
android:hint="@string/notice_content_load" |
||||
android:importantForAutofill="no" |
||||
android:inputType="none|textMultiLine" /> |
||||
</LinearLayout> |
||||
</ScrollView> |
||||
|
||||
<TextView |
||||
android:id="@+id/notice_author" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="end" |
||||
android:textSize="24sp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@id/content" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/notice_time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="end" |
||||
android:textSize="24sp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@id/notice_author" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading…
Reference in new issue