该 类的全部源码为:
GridViewExt package com.yaomei.widget; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import com.yaomei.activity.adapter.AppsAdapter; import com.yaomei.activity.info.R; public class gridViewExt extends LinearLayout { public List<HashMap<String, Object>> tableRowsList; private List<HashMap<String, Object>> app = new ArrayList<HashMap<String, Object>>(); private AppsAdapter adapter; onItemClickListener onItemClickEvent; onLongPressExt onLongPress; int checkRowID = -1; // 选中行的下标 int checkColumnID = -1; // 选中列的下标 int lastRowCount = -1; // 最后一行的总数 private int ColumnCount; // 每列的总数 public void setColumnCount(int count) { this.ColumnCount = count; } public int getColumnCount() { return ColumnCount; } public interface onItemClickListener { public boolean onItemClick(int position, MotionEvent event, View view); } public interface onLongPressExt { public boolean onLongPress(View view); } public gridViewExt(Context context) { this(context, null); // TODO Auto-generated constructor stub } public gridViewExt(Context context, AttributeSet attrs) { super(context, attrs); int resouceID = -1; TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.GridViewExt); int N = typedArray.getIndexCount(); for (int i = 0; i < N; i++) { int attr = typedArray.getIndex(i); switch (attr) { case R.styleable.GridViewExt_ColumnCount: resouceID = typedArray.getInt( R.styleable.GridViewExt_ColumnCount, 0); setColumnCount(resouceID); break; } } typedArray.recycle(); } public void setOnItemClickListener(onItemClickListener click) { this.onItemClickEvent = click; } public void setOnLongPressListener(onLongPressExt longPress) { this.onLongPress = longPress; } public void NotifyDataChange() { removeAllViews(); } void bindView() { removeAllViews(); int count = adapter.getCount(); TableCell[] cell = null; int j = 0; LinearLayout layout; tableRowsList = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < count; i++) { j++; final int position = i; if (j > getColumnCount() || i == 0) { cell = new TableCell[getColumnCount()]; } final View view = adapter.getView(i, null, null); view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub unCheckPressed(); checkRowID = -1; checkColumnID = -1; if (onItemClickEvent != null) { onItemClickEvent.onItemClick(position, event, view); } return false; } });