• 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;


      }

  • 相关阅读:
    错误 1 类,结构或接口成员声明中的标记"="无效
    转asp.net中的App_GlobalResources和App_LocalResources使用
    input type=file 上传文件样式美化(转载)
    Postman Post请求上传文件
    vuex 、store、state (转载)
    ES5、ES2015、ECMAScript6(转载)
    axios 用法简介(转载)
    js中const,var,let区别(转载)
    C#开发微信公众平台-就这么简单(附Demo)转载
    什么是 Native、Web App、Hybrid、React Native 和 Weex?(转载)
  • 原文地址:https://www.cnblogs.com/awandxx/p/5283809.html
Copyright © 2020-2023  润新知