package com.example.memosystem.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.memosystem.R;
import com.example.memosystem.activity.AddActivity;
import com.example.memosystem.bean.Record;

import java.util.List;

public class RecordAdapter extends ArrayAdapter<Record> {


    private List<Record> items;
    public RecordAdapter( Context context, List<Record> items) {
        super(context, R.layout.manage_list,items);
        this.items=items;
    }



    @Override
    public View getView(int position,View convertView,ViewGroup parent) {

        if( convertView==null){

            LayoutInflater inflater=LayoutInflater.from(getContext());
            convertView=inflater.inflate(R.layout.manage_list,parent,false);
        }


        TextView title=convertView.findViewById(R.id.title);
        TextView con=convertView.findViewById(R.id.con);
        TextView time=convertView.findViewById(R.id.time);






        Record res = items.get(position);
        title.setText(res.getTitle());
        con.setText(res.getCon());
        time.setText(res.getTim());

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(getContext(), AddActivity.class);//目标i界面
                intent.putExtra("sta","1");
                intent.putExtra("account",res.getUid());//账号
                intent.putExtra("id",res.getId());
                intent.putExtra("title",res.getTitle());
                intent.putExtra("con",res.getCon());
                intent.putExtra("time",res.getTim());
                getContext().startActivity(intent);//打开目标界面
            }
        });
        return convertView;
    }
}
