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;


      }

  • 相关阅读:
    使用SQL Server Management Studio 创建数据库备份作业
    ClickOnce 获取客户端发布版本号
    在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求
    找不到方法:“Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)
    常用操作类
    数据库命名规范
    expression动态构成
    C# 获得当前方法 和 方法调用链 的 方法
    EF架构封装类
    基于微软企业库的分层代码框架
  • 原文地址:https://www.cnblogs.com/awandxx/p/5283809.html
Copyright © 2011-2022 走看看