zoukankan      html  css  js  c++  java
  • 2021.3.2

    添加适配器,把获取的数据按照格式显示在主界面,在Java里新建Class,命名为ListAp

    package com.example.myaccountapp;

    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Adapter;
    import android.widget.BaseAdapter;
    import android.widget.TextView;

    import java.util.List;

    public class ListAp extends BaseAdapter {
    List<costList> mList;

    public ListAp(List<costList>list)
    {
    mList=list;
    }

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

    @Override
    public Object getItem(int position) {
    return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
    return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    View view=mLayoutInflater.inflate(R.layout.list_item,null);
    //取出数据赋值
    costList item=mList.get(position);
    TextView tv_title=view.findViewById(R.id.tv_title);
    TextView tv_date=view.findViewById(R.id.tv_date);
    TextView tv_money=view.findViewById(R.id.tv_money);
    //绑定
    tv_title.setText(mList.get(position).getTitle());
    tv_date.setText(mList.get(position).getDate());
    tv_money.setText(mList.get(position).getMoney());
    return view;

    }

    private List<costList>getmList;
    private LayoutInflater mLayoutInflater;

    public ListAdapter(Context context,List<costList>list)
    {
    mList=list;
    //通过外部传来的Context初始化LayoutInflater对象
    mLayoutInflater=LayoutInflater.from(context);
    }
    }

  • 相关阅读:
    python_网络编程struct模块解决黏包问题
    python_网络编程socket(UDP)
    python_网络编程socket(TCP)
    python_面向对象
    python_生成器
    python_迭代器
    linux实操_shell自定义函数
    linux实操_shell系统函数
    linux实操_shell读取控制台输入
    scrapy-redis 0.6.8 配置信息
  • 原文地址:https://www.cnblogs.com/SirNie/p/14910998.html
Copyright © 2011-2022 走看看