parent
a9560edcd8
commit
909cdbf717
@ -0,0 +1,38 @@
|
||||
package com.example.leudaemialikeme.Activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.example.leudaemialikeme.Adapter.EventAdapter;
|
||||
import com.example.leudaemialikeme.Event;
|
||||
import com.example.leudaemialikeme.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EventActivity extends AppCompatActivity {
|
||||
|
||||
private List<Event> mData = new ArrayList<>();
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_event);
|
||||
getData();//获得数据
|
||||
RecyclerView recycleView = (RecyclerView) findViewById(R.id.eventList);//获得视图
|
||||
LinearLayoutManager layoutManager;
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recycleView.setLayoutManager(layoutManager);//建立线性布局
|
||||
EventAdapter adapter = new EventAdapter(mData);//创建适配器
|
||||
recycleView.setAdapter(adapter);//将视图与适配器连接起来
|
||||
}
|
||||
|
||||
private void getData() {
|
||||
Event event1 = new Event("04","10月","第三次化疗","08:00");
|
||||
mData.add(event1);
|
||||
Event event2 = new Event("11","5月","检查","09:00");
|
||||
mData.add(event2);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.example.leudaemialikeme.Adapter;
|
||||
|
||||
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.example.leudaemialikeme.Event;
|
||||
import com.example.leudaemialikeme.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventAdapter extends RecyclerView.Adapter<EventAdapter.ViewHolder>{
|
||||
private List<Event> meventList;
|
||||
|
||||
//重写构造方法
|
||||
public EventAdapter(List<Event> meventList){
|
||||
this.meventList = meventList;
|
||||
}
|
||||
public int getItemCount(){
|
||||
return meventList.size();
|
||||
}
|
||||
//内部类
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView event_day,event_month,event_info,event_time;
|
||||
|
||||
public ViewHolder(@NonNull View itemView){
|
||||
super(itemView);
|
||||
this.event_day = (TextView)itemView.findViewById(R.id.event_day);
|
||||
this.event_month = (TextView)itemView.findViewById(R.id.event_month);
|
||||
this.event_info = (TextView)itemView.findViewById(R.id.event_info);
|
||||
this.event_time = (TextView)itemView.findViewById(R.id.event_time);
|
||||
}
|
||||
}
|
||||
//重写 onCreateViewHolder()方法
|
||||
@Override
|
||||
public EventAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.event_item,parent,false);
|
||||
EventAdapter.ViewHolder holder=new EventAdapter.ViewHolder(view);
|
||||
return holder;
|
||||
}
|
||||
//重写onBindViewHolder()方法
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder,int position){
|
||||
Event event = meventList.get(position);
|
||||
holder.event_day.setText(event.getEvent_day());
|
||||
holder.event_month.setText(event.getEvent_month());
|
||||
holder.event_info.setText(event.getEvent_info());
|
||||
holder.event_time.setText(event.getEvent_time());
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.example.leudaemialikeme;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Event implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
//声明所有的变量
|
||||
private String event_day;
|
||||
private String event_month;
|
||||
private String event_info;
|
||||
private String event_time;
|
||||
|
||||
public Event(String event_day,String event_month,String event_info,String event_time){
|
||||
this.event_day = event_day;
|
||||
this.event_info = event_info;
|
||||
this.event_month =event_month;
|
||||
this.event_time = event_time;
|
||||
}
|
||||
public String getEvent_day() {
|
||||
return event_day;
|
||||
}
|
||||
|
||||
public void setEvent_day(String event_day) {
|
||||
this.event_day = event_day;
|
||||
}
|
||||
|
||||
public String getEvent_month() {
|
||||
return event_month;
|
||||
}
|
||||
|
||||
public void setEvent_month(String event_month) {
|
||||
this.event_month = event_month;
|
||||
}
|
||||
|
||||
public String getEvent_info() {
|
||||
return event_info;
|
||||
}
|
||||
|
||||
public void setEvent_info(String event_info) {
|
||||
this.event_info = event_info;
|
||||
}
|
||||
|
||||
public String getEvent_time() {
|
||||
return event_time;
|
||||
}
|
||||
|
||||
public void setEvent_time(String event_time) {
|
||||
this.event_time = event_time;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.example.leudaemialikeme.Activity.EventActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_margin="15dp"
|
||||
android:src="@mipmap/img_go_answer_return" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView30"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="18dp"
|
||||
android:layout_margin="15dp"
|
||||
android:gravity="center"
|
||||
android:text="大事记" />
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_margin="15dp"
|
||||
android:src="@mipmap/img_add"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/shape_round_corner"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/eventList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_day"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="28dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_month"
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginLeft="-10dp"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="6"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:background="@color/white"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="start"
|
||||
android:src="@mipmap/event_dot"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="18dp"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_weight="3"
|
||||
android:textSize="12dp" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_gravity="right"
|
||||
android:src="@mipmap/img_go_more" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
After Width: | Height: | Size: 218 B |
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in new issue