zoukankan      html  css  js  c++  java
  • 2月10日

    完成安卓的记账本的基本框架的构成:主要今天完成的是外框和fragment和适配器

    适配器的代码

    package com.eb.writeaccount;
    
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Switch;
    import android.widget.TextView;
    
    import androidx.annotation.NonNull;
    import androidx.recyclerview.widget.DiffUtil;
    import androidx.recyclerview.widget.ListAdapter;
    import androidx.recyclerview.widget.RecyclerView;
    
    public class MyAdapter extends ListAdapter<Word,MyAdapter.MyViewHolder> {
    
        private MyViewModel myViewModel;
        MyAdapter( MyViewModel wordViewModel) {
            super(new DiffUtil.ItemCallback<Word>() {
                @Override
                public boolean areItemsTheSame(@NonNull Word oldItem, @NonNull Word newItem) {
                    return oldItem.getId() == newItem.getId();
                }
    
                @Override
                public boolean areContentsTheSame(@NonNull Word oldItem, @NonNull Word newItem) {
                    return (oldItem.getMoney().equals(newItem.getMoney())
                            && oldItem.getAtime().equals(newItem.getMoney())
                           );
                }
            });
    
            this.myViewModel = wordViewModel;
        }
    
        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
            View itemView;
            itemView = layoutInflater.inflate(R.layout.word,parent,false);
            final MyViewHolder holder = new MyViewHolder(itemView);
            return holder;
        }
    
        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            final Word word = getItem(position);
            holder.textViewNumber.setText(String.valueOf(position + 1));
            holder.textViewmoney.setText(word.getMoney());
            holder.textViewtime.setText(word.getAtime());
        }
        public void onViewAttachedToWindow(@NonNull MyViewHolder holder) {
            super.onViewAttachedToWindow(holder);
            holder.textViewNumber.setText(String.valueOf(holder.getAdapterPosition() + 1));
        }
        static class MyViewHolder extends RecyclerView.ViewHolder {
            TextView textViewNumber,textViewmoney,textViewtime;
    
    
            MyViewHolder(@NonNull View itemView) {
                super(itemView);
                textViewNumber = itemView.findViewById(R.id.textViewnumber);
                textViewmoney = itemView.findViewById(R.id.textViewmoney);
                textViewtime = itemView.findViewById(R.id.textViewtime);
    
    
            }
        }
    }
  • 相关阅读:
    [转][Linux/Ubuntu] vi/vim 使用方法讲解
    [转]在Windows中安装Memcached
    memcached可视化客户端工具
    [转]C#操作Memcached帮助类
    [转]Redis和Memcache区别,优缺点对比
    [转]【转】大型高性能ASP.NET系统架构设计
    [转]浅谈命令查询职责分离(CQRS)模式
    element-UI——el-table添加序号
    xss攻击(转)
    vuex原理
  • 原文地址:https://www.cnblogs.com/guziteng1/p/12323736.html
Copyright © 2011-2022 走看看