Android Open Source - FrameLite Frame Base Adapter






From Project

Back to project page FrameLite.

License

The source code is released under:

GNU General Public License

If you think the Android project FrameLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.miku.framelite.adapter;
//w w w  .  jav  a  2s . c om
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * ??????ViewHolder?Adapter??????<br>
 * ??????createItemHolder?bindData?createItemView????<br>
 * 
 * ??:<br>
 *  public class MyHolder extends ViewHolder<br>
 *   {<br>
 *      public TextView itemView;<br>
 *   }<br>
 * <br>
 * protected ViewHolder createItemHolder(View convertView)<br>
 *   {<br>
 *       MyHolder holder = new MyHolder();<br>
 *       holder.activityItem = (TextView)convertView.findViewById(R.id.activity_name);<br>
 *       return holder;<br>
 *   }<br>
 *<br>
 *   protected void bindData(String data,int position, View convertView, ViewGroup parent, ViewHolder h)<br>
 *   {<br>
 *       MyHolder holder = (MyHolder)h;<br>
 *       holder.itemView.setText(data);<br>
 *   }<br>
 *
 *   public View createItemView(Context context)<br>
 *   {<br>
 *       return View.inflate(context,R.layout.item_view,null);<br>
 *   }<br>
 * <br>
 * @author xr.lee
 *
 * @param <T> ??????item?????????
 */
public abstract class FrameBaseAdapter<T> extends BaseAdapter
{
    protected Context mContext;

    protected List<T> mData = new ArrayList<T>();

    protected class ViewHolder
    {
    }
    
    public FrameBaseAdapter(Context context){
      init(context);
    }

    public FrameBaseAdapter(Context context, List<T> dataList)
    {
      init(context);
        this.mData = dataList;
    }
    
    
    private void init(Context context){
      mContext = context;
    }

    protected abstract ViewHolder createItemHolder(View convertView);
    protected abstract void bindData(T data,int position, View convertView, ViewGroup parent, ViewHolder holder);
    public abstract View createItemView(Context context);
    
    public void setDataList(List<T> dataList){
      this.mData = dataList;
      this.notifyDataSetChanged();
    }
    
    public List<T> getDataList(){
      return this.mData;
    }
    
    public void clearAllDatas(){
      this.mData.clear();
      this.notifyDataSetChanged();
    }
    
    public void addData(T data){
      this.mData.add(data);
    }
    
    public void removeData(int position){
      this.mData.remove(position);
    }
    
    public void removeData(T data){
      this.mData.remove(data);
    }

    @Override
    public int getCount() {
        int count = mData != null?mData.size():0;
        return count;
    }

    @Override
    public T getItem(int position) {
      return mData==null?null:mData.get(position);
    }

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

    @SuppressWarnings("unchecked")
  @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;
        if (convertView == null ) {
            convertView = createItemView(mContext);
            holder = createItemHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder)convertView.getTag();
        bindData(getItem(position),position, convertView, parent, holder);
        return convertView;
    }
}




Java Source Code List

com.miku.framelite.FrameApplication.java
com.miku.framelite.FrameBaseActivity.java
com.miku.framelite.FrameOrmBaseActivity.java
com.miku.framelite.adapter.FrameBaseAdapter.java
com.miku.framelite.annotations.ViewInject.java
com.miku.framelite.api.BaseRequest.java
com.miku.framelite.api.IRequest.java
com.miku.framelite.api.RetResult.java
com.miku.framelite.api.core.Executor.java
com.miku.framelite.api.database.AbstractDatabaseRequest.java
com.miku.framelite.api.database.AbstractOrmDatabaseRequest.java
com.miku.framelite.api.database.DatabaseQueryRequest.java
com.miku.framelite.api.database.DatabaseType.java
com.miku.framelite.api.http.AbstractHttpRequest.java
com.miku.framelite.api.http.HttpStringGetRequest.java
com.miku.framelite.api.http.HttpStringPostRequest.java
com.miku.framelite.api.http.HttpType.java
com.miku.framelite.api.webservice.AbstractWebServiceRequest.java
com.miku.framelite.api.webservice.WebServiceConnectionSE.java
com.miku.framelite.api.webservice.WebServiceHttpTransportSE.java
com.miku.framelite.api.webservice.WebServiceJsonRequest.java
com.miku.framelite.api.webservice.WebServiceStringRequest.java
com.miku.framelite.httpx.IDownloadHandler.java
com.miku.framelite.httpx.IHttpX.java
com.miku.framelite.httpx.core.DownloadHandler.java
com.miku.framelite.httpx.core.HttpX.java
com.miku.framelite.services.CrashHandler.java
com.miku.framelite.utils.BitmapUtils.java
com.miku.framelite.utils.DateUtils.java
com.miku.framelite.utils.DimensionUtils.java
com.miku.framelite.utils.EncryptionUtils.java
com.miku.framelite.utils.HttpUtils.java
com.miku.framelite.utils.Log.java
com.miku.framelite.utils.TelePhoneUtils.java
com.miku.framelite.utils.ViewUtils.java