package com.base.baseandroid; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import java.util.List; public abstract class CommonAdapter創(chuàng)新互聯(lián)成立于2013年,先為拉薩等服務建站,拉薩等地企業(yè),進行企業(yè)商務咨詢服務。為拉薩企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。extends BaseAdapter { private Context mContext; private List mDatas; private int mLayoutId; public CommonAdapter(Context context, List datas, int layoutId) { this.mContext = context; this.mDatas = datas; this.mLayoutId = layoutId; } @Override public int getCount() { return mDatas.size(); } @Override public T getItem(int position) { return mDatas.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = ViewHolder.get(mContext, convertView, mLayoutId, position); setValueForView(holder, getItem(position)); return holder.getConvertView(); } public abstract void setValueForView(ViewHolder holder, T t); } package com.base.baseandroid; import com.lidroid.xutils.BitmapUtils; import android.content.Context; import android.graphics.Bitmap; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.TextView; public class ViewHolder { private SparseArray mViews; protected int mPosition; private View mConvertView; private Context context; private BitmapUtils bitmapUtils; public View getConvertView() { return mConvertView; } public ViewHolder(Context context, int layoutId, int position) { this.mPosition = position; this.mViews = new SparseArray (); this.context = context; bitmapUtils = new BitmapUtils(context); mConvertView = LayoutInflater.from(context).inflate(layoutId, null); mConvertView.setTag(this); } public static ViewHolder get(Context context, View convertView, int layoutId, int position) { if (convertView == null) { return new ViewHolder(context, layoutId, position); } else { ViewHolder holder = (ViewHolder) convertView.getTag(); holder.mPosition = position; // 注意:這句代碼是必須的,否則復用的時候position會出錯 return holder; } } public T getViewById(int viewId) { View view = mViews.get(viewId); if (view == null) { view = getConvertView().findViewById(viewId); mViews.put(viewId, view); } return (T) view; } public ViewHolder setText(int viewId, String text) { TextView textView = getViewById(viewId); textView.setText(text); return this; } public ViewHolder setImageResource(int viewId, int resId) { ImageView p_w_picpathView = getViewById(viewId); p_w_picpathView.setImageResource(resId); return this; } public ViewHolder setImageBitmap(int viewId, Bitmap bitmap) { ImageView p_w_picpathView = getViewById(viewId); p_w_picpathView.setImageBitmap(bitmap); return this; } public ViewHolder setImg(int viewId, String url) { ImageView p_w_picpathView = getViewById(viewId); bitmapUtils.display(p_w_picpathView, url); return this; } public ViewHolder setImgOnClick(int viewId, OnClickListener onClickListener) { ImageView p_w_picpathView = getViewById(viewId); p_w_picpathView.setOnClickListener(onClickListener); return this; } } package com.base.adapter; import java.util.List; import android.content.Context; import android.view.View; import android.view.View.OnClickListener; import android.widget.Toast; import com.base.baseandroid.CommonAdapter; import com.base.baseandroid.ViewHolder; import com.base.bean.CountryBean; import com.example.baseandroid.R; public class MyAdapter extends CommonAdapter { private Context context; public MyAdapter(Context context, List data, int layoutId) { super(context, data, layoutId); this.context = context; } @Override public void setValueForView(ViewHolder holder, final CountryBean bean) { holder.setText(R.id.tv_list_country, bean.getcCountryName()); holder.setImg(R.id.iv_list_country, bean.getFlagImage()); holder.setImgOnClick(R.id.iv_list_country, new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, bean.getcCountryName(), 1).show(); } }); } }
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。