zoukankan      html  css  js  c++  java
  • 灭霸-个人冲刺第九天

    1, 昨天的成就:

      a)       完成的任务:失物招领页面完善,框架接近完美

      b)       所花时间:6h

      c)        还剩余2h

    2, 遇到的困难:

    a)     算法整理很困难,初步认为先用标签,更改了表结构,让表结构接近完美,可以充分通过表信息,进行对每一个用户进行建表,以此,充分得知用户的喜好,再根据这些喜好,进行推荐。

    3, 今天的任务:

    a)           转战表白墙设计

      1 package com.weicent.android.csma.adapter;
      2 
      3 import android.content.Context;
      4 import android.util.SparseArray;
      5 import android.view.View;
      6 import android.view.ViewGroup;
      7 import android.widget.BaseAdapter;
      8 
      9 import java.util.ArrayList;
     10 import java.util.List;
     11 
     12 
     13 /**
     14  * 泛型数据适配器
     15  */
     16 public abstract class SimpleBaseAdapter<T> extends BaseAdapter {
     17     protected Context context;
     18     protected List<T> data;
     19     protected boolean busy = false;
     20 
     21     public SimpleBaseAdapter(Context context, List<T> data) {
     22         this.context = context;
     23         this.data = data == null ? new ArrayList<T>() : data;
     24     }
     25 
     26     @Override
     27     public int getCount() {
     28         return data.size();
     29     }
     30 
     31     @Override
     32     public T getItem(int position) {
     33         if (position >= data.size())
     34             return null;
     35         return data.get(position);
     36     }
     37 
     38     @Override
     39     public long getItemId(int position) {
     40         return position;
     41     }
     42 
     43     /**
     44      * 该方法需要子类实现,需要返回item布局的resource id
     45      *
     46      * @return
     47      */
     48     public abstract int getItemResource();
     49 
     50     /**
     51      * 滑动状态
     52      *
     53      * @param busy
     54      */
     55     public void setBusy(boolean busy) {
     56         this.busy = busy;
     57     }
     58 
     59     /**
     60      * 使用该getItemView方法替换原来的getView方法,需要子类实现
     61      *
     62      * @param position
     63      * @param convertView
     64      * @param parent
     65      * @param holder
     66      * @return
     67      */
     68     public abstract View getItemView(int position, View convertView, ViewHolder holder);
     69 
     70     //public abstract View getItemView(int position, View convertView);
     71     @SuppressWarnings("unchecked")
     72     @Override
     73     public View getView(int position, View convertView, ViewGroup parent) {
     74         ViewHolder holder;
     75         if (null == convertView) {
     76             convertView = View.inflate(context, getItemResource(), null);
     77             holder = new ViewHolder(convertView);
     78             convertView.setTag(holder);
     79         } else {
     80             holder = (ViewHolder) convertView.getTag();
     81         }
     82         return getItemView(position, convertView, holder);
     83     }
     84 
     85     //通过布局ID并使用布局中的ID识别控件
     86     public class ViewHolder {
     87         private SparseArray<View> views = new SparseArray<>();
     88         private View convertView;
     89 
     90         public ViewHolder(View convertView) {
     91             this.convertView = convertView;
     92         }
     93 
     94         @SuppressWarnings("unchecked")
     95         public <T extends View> T getView(int resId) {
     96             View v = views.get(resId);
     97             if (null == v) {
     98                 v = convertView.findViewById(resId);
     99                 views.put(resId, v);
    100             }
    101             return (T) v;
    102         }
    103     }
    104 
    105     //添加Item
    106     public void addAll(List<T> elem) {
    107         data.addAll(elem);
    108         notifyDataSetChanged();
    109     }
    110 
    111     //插入Item
    112     public void insert(List<T> elem) {
    113         data.addAll(0, elem);
    114         notifyDataSetChanged();
    115     }
    116 
    117     //移除来自T 也就是model的Item
    118     public void remove(T elem) {
    119         if (elem != null) {
    120             data.remove(elem);
    121         }
    122         notifyDataSetChanged();
    123     }
    124 
    125     //移除来自index 索引的Item
    126     public void remove(int index) {
    127         data.remove(index);
    128         notifyDataSetChanged();
    129     }
    130 
    131     //替换所有Item
    132     public void update(List<T> elem) {
    133         if (elem != null) {
    134             data.clear();
    135             data.addAll(elem);
    136         }
    137         notifyDataSetChanged();
    138     }
    139 
    140     //清除全部的Item
    141     public void clearAll() {
    142         data.clear();
    143         notifyDataSetChanged();
    144     }
    145 }

     

     

     

  • 相关阅读:
    PHP学习笔记之继承(面向对象三大特性之一)
    php学习笔记之封装练习题
    PHP学习笔记---封装(面向对象三大特性之一)
    PHP学习笔记之面向对象(上)
    php学习笔记之数组遍历练习题1
    php学习笔记数组与数据结构1(数组)
    php学习笔记数组与数据结构1(日期时间函数及遇到的问题解决)
    顺序查找和二分法查找
    冒泡排序
    字符串类型的一些操作处理
  • 原文地址:https://www.cnblogs.com/smartisn/p/10804794.html
Copyright © 2011-2022 走看看