码迷,mamicode.com
首页 > 其他好文 > 详细

项目开发第三天

时间:2020-02-16 23:26:04      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:wpa   false   style   textview   text   setimage   class   listview   find   

今天主要做收入支出的listview,recycleview展示方法。

package net.hnjdzy.tinyaccount.adapter;

import java.util.List;

import net.hnjdzy.tinyaccount.R;
import net.hnjdzy.tinyaccount.entity.AccountItem;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 收入列表的适配器
 * @author androiddev@163.com,hnjdzy
 */
public class AccountItemAdapter extends BaseAdapter {
    private List<AccountItem> mItems;
    private LayoutInflater mInflater;

    //构造函数
    public AccountItemAdapter(List<AccountItem> items, Activity context){
        this.mItems = items;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {   //要显示的行数
        return this.mItems.size();
    }

    @Override
    public Object getItem(int arg0) {  //某行要显示的数据
        return this.mItems.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {  //某行的数据ID
        return this.mItems.get(arg0).getId();
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        //从布局填充得到一个view
        View view = this.mInflater.inflate(R.layout.list_view_item, null);

        //找到View上的组件
        TextView tvCategory = (TextView)view.findViewById(R.id.textViewCategory);
        TextView tvRemark = (TextView)view.findViewById(R.id.textViewRemark);
        TextView tvMoney = (TextView)view.findViewById(R.id.textViewMoney);
        TextView tvDate = (TextView)view.findViewById(R.id.textViewDate);
        ImageView imageView = (ImageView)view.findViewById(R.id.imageViewIcon);

        //把数据设置到对应的组件
        AccountItem item = this.mItems.get(arg0);
        tvCategory.setText(item.getCategory());
        tvRemark.setText(item.getRemark());
        tvMoney.setText(String.valueOf(item.getMoney()));
        tvDate.setText(item.getDate());
        int icon = R.drawable.baby_icon;  //测试
        if (icon>0){
            imageView.setImageResource(icon);
        }
        return view;
    }

}
package net.hnjdzy.tinyaccount.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.hnjdzy.tinyaccount.R;
import net.hnjdzy.tinyaccount.entity.AccountItem;

import java.util.List;

/**
 * 支出列表的适配器
 * @author androiddev@163.com,hnjdzy
 */
public class OutlayRecyclerViewAdapter extends RecyclerView.Adapter<OutlayRecyclerViewAdapter.NormalTextViewHolder> {
        private final LayoutInflater mLayoutInflater;
        private List<AccountItem> mItems;

        public OutlayRecyclerViewAdapter(Activity context, List<AccountItem> items) {
            mLayoutInflater = LayoutInflater.from(context);
            mItems = items;
        }

        @Override
        public NormalTextViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new NormalTextViewHolder(mLayoutInflater.inflate(R.layout.recyclerview_item, parent, false));
        }

        @Override
        public void onBindViewHolder(NormalTextViewHolder holder, int position) {
            //把数据设置到对应的组件
            AccountItem item = this.mItems.get(position);
            holder.tvCategory.setText(item.getCategory());
            holder.tvRemark.setText(item.getRemark());
            holder.tvMoney.setText(String.valueOf(item.getMoney()));
            holder.tvDate.setText(item.getDate());
            int icon = R.drawable.book_icon;  //测试
            if (icon>0){
                holder.imageView.setImageResource(icon);
            }
        }

        @Override
        public int getItemCount() {
            return mItems == null ? 0 : mItems.size();
        }

        public static class NormalTextViewHolder extends RecyclerView.ViewHolder {

            TextView tvCategory;
            TextView tvRemark;
            TextView tvMoney;
            TextView tvDate;
            ImageView imageView;

            NormalTextViewHolder(View view) {
                super(view);
                tvCategory = (TextView)view.findViewById(R.id.textViewCategory);
                tvRemark = (TextView)view.findViewById(R.id.textViewRemark);
                tvMoney = (TextView)view.findViewById(R.id.textViewMoney);
                tvDate = (TextView)view.findViewById(R.id.textViewDate);
                imageView = (ImageView)view.findViewById(R.id.imageViewIcon);

            }
    }
}

 



package net.hnjdzy.tinyaccount.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
* 主界面底部导航对应的Viewpager适配器
* @author androiddev@163.com,hnjdzy
*/
public class ViewPagerAdapter extends FragmentPagerAdapter {

private final List<Fragment> mFragmentList = new ArrayList<>();

public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}

@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}

@Override
public int getCount() {
return mFragmentList.size();
}

public void addFragment(Fragment fragment) {
mFragmentList.add(fragment);
}

}
 

项目开发第三天

标签:wpa   false   style   textview   text   setimage   class   listview   find   

原文地址:https://www.cnblogs.com/w669399221/p/12319396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!