編輯:關於Android編程
有了這個CommonAdapter以後的Adapter就so easy 了。
1. 定義CommonAdapter
package com.stephen.ifishing.adapter; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; /** * * @author Stephen Huang * * @param2. 輔助類ViewHolder*/ public abstract class CommonAdapter extends BaseAdapter { protected Context mContext; protected List mDatas; protected LayoutInflater mInflater; protected int layoutId; public CommonAdapter(Context context, List data, int layoutId) { this.mContext = context; mInflater = LayoutInflater.from(context); this.mDatas = data; this.layoutId = 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; } public void onDataChange(List data) { this.mDatas = data; this.notifyDataSetChanged(); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = ViewHolder.get(mContext, convertView, parent, layoutId, position); convert(holder, mDatas.get(position)); return holder.getConvertView(); } public abstract void convert(ViewHolder holder, T t); }
package com.stephen.ifishing.adapter; import android.content.Context; import android.graphics.Bitmap; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; /** * * @author Stephen Huang * */ public class ViewHolder { private SparseArraymViews; private int mPostion; private View mConvertView; public ViewHolder(Context context, ViewGroup parent, int layoutId, int postion) { this.mPostion = postion; this.mViews = new SparseArray (); this.mConvertView = LayoutInflater.from(context).inflate(layoutId, null); mConvertView.setTag(this); } public static ViewHolder get(Context context, View convertView, ViewGroup parent, int layoutId, int postion) { if (convertView == null) { return new ViewHolder(context, parent, layoutId, postion); } else { ViewHolder holder = (ViewHolder)convertView.getTag(); holder.mPostion = postion; return holder; } } /** * 通過viewId獲取控件 * @param viewId * @return */ public T getView(int viewId) { View view = mViews.get(viewId); if (view == null) { view = mConvertView.findViewById(viewId); mViews.put(viewId, view); } return (T) view; } public View getConvertView() { return mConvertView; } public ViewHolder setText(int viewId, String text) { TextView tv = getView(viewId); tv.setText(text); return this; } public ViewHolder setImageResource(int viewId, int resId) { ImageView iv = getView(viewId); iv.setImageResource(resId); return this; } public ViewHolder setImageBitmap(int viewId, Bitmap bm) { ImageView iv = getView(viewId); iv.setImageBitmap(bm); return this; } }
package com.stephen.ifishing.adapter; import java.util.List; import com.stephen.ifishing.R; import com.stephen.ifishing.model.ShowFishingItem; import android.content.Context; /** * * @author Stephen Huang * */ public class ShowFishingAdapter extends CommonAdapter{ public ShowFishingAdapter(Context context, List itemList) { super(context, itemList, R.layout.show_fishing); } @Override public void convert(ViewHolder holder, ShowFishingItem bean) { holder.setText(R.id.tv_user_name, bean.userName) .setText(R.id.tv_say_something, bean.saySomething) .setImageResource(R.id.iv_portrait, bean.portraitImageResId); } }
當我們第一次下載QQ並且打開的時候,會有一個新手引導,引導是幾張圖片,再加上一些文字說明,向右滑動,直到結束,今天一大早起來研究了一下關於此種效果的實現之ViewPage
Blur自從iOS系統引入了Blur效果,也就是所謂的毛玻璃、模糊化效果,磨砂效果,各大系統就開始競相模仿,這是一個怎樣的效果呢,我們現來看一些圖:這些就是典型的Blur
目錄:1.ListView概述2.ListView使用中的重要角色(Adapter,ViewHolder,數據集,布局)3.ListView常用屬性4.ListView+
Android中有兩種主要方式使用Service,通過調用Context的startService方法或調用Context的bindService方法,本文只探討純bin