zoukankan      html  css  js  c++  java
  • Android之ListView优化

    public class MyAdapter extends BaseAdapter {
      private Context context;
      public List<Students> list;
      private LayoutInflater mLayoutInflater;

      public MyAdapter (Context context, List<Students> list) {
        this.context = context;
        this.list= list;
        mLayoutInflater = LayoutInflater.from(context);

      }

      @Override
      public int getCount() {
        return list.size();
      }
      @Override
      public Object getItem(int position) {
        return list.get(position);
      }
      @Override
      public long getItemId(int position) {

        return position;
      }
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
          holder = new ViewHolder();

          convertView= mLayoutInflater.inflate(R.layout.students_item,null);
          holder.name=(TextView)convertView.findViewById(R.id.tv_name);
          holder.money = (TextView)convertView.findViewById(R.id.tv_money);
          holder.time= (TextView)convertView.findViewById(R.id.tv_time);

          //设置控件集到convertView
          convertView.setTag(holder);
        }
        else
        {
          holder = (ViewHolder)convertView.getTag();
        }
        Students students = list.get(position);
        //更新布局内容
        String name = students .getName();
        String amount = students .getMoney();

        String time = students .getDate();
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        SimpleDateFormat sdf2 = new SimpleDateFormat( "MM-dd" );

        try {
          Date date = sdf.parse( time );
          String time2 = sdf2.format(date);
          holder.time.setText(time2);
          holder.name.setText(name);
          holder.money.setText(amount);
        } catch (ParseException e) {
          e.printStackTrace();
      }


      return convertView;
    }
      private static class ViewHolder {

        TextView name;
        TextView money;
        TextView time;


      }

  • 相关阅读:
    splunk linux安装
    [读书笔记]-时间管理-把时间当做朋友
    [读书笔记]-技术学习-Redis
    [读书笔记]-阅读方法-王者速读法
    vuex、localStorage、sessionStorage之间的区别
    vuex的使用
    Vue常用指令总结
    vue-router参数传递
    Vue-router的基本使用
    v-on精炼
  • 原文地址:https://www.cnblogs.com/awandxx/p/5283809.html
Copyright © 2011-2022 走看看