ListViewソース学習ノート[オリジナル]
6534 ワード
ListViewソース学習ノート
いくつかの重要なクラスと方法があります
次のmIsCacheColorOpaqueは背景の透明色に関するものです.
下の
public class ListView extends AbsListView {
/**
* Used to indicate a no preference for a position type.
*
*/
static final int NO_POSITION = -1;
/**
* Normal list that does not indicate choices
* ( )
*/
public static final int CHOICE_MODE_NONE = 0;
/**
* The list allows up to one choice
*
*/
public static final int CHOICE_MODE_SINGLE = 1;
/**
* The list allows multiple choices
*
*/
public static final int CHOICE_MODE_MULTIPLE = 2;
/**
* When arrow scrolling, ListView will never scroll more than this factor times the height of the list.
*
*/
private static final float MAX_SCROLL_FACTOR = 0.33f;
/**
* When arrow scrolling, need a certain amount of pixels to preview next items. This is usually the fading edge,
* but if that is small enough, we want to make sure we preview at least this many pixels.
*
*/
private static final int MIN_SCROLL_PREVIEW_PIXELS = 2;
いくつかの重要なクラスと方法があります
public void setSelection(int position)
public void setCacheColorHint(int color)
public void setChoiceMode(int choiceMode)
public boolean performItemClick(View view, int position, long id)
public void setItemChecked(int position, boolean value)
次のmIsCacheColorOpaqueは背景の透明色に関するものです.
private boolean mIsCacheColorOpaque;
@Override
public boolean isOpaque() {
return (mCachingStarted && mIsCacheColorOpaque && mDividerIsOpaque &&
hasOpaqueScrollbars()) || super.isOpaque();
}
@Override
public void setCacheColorHint(int color) {
final boolean opaque = (color >>> 24) == 0xFF;
mIsCacheColorOpaque = opaque;
if (opaque) {
if (mDividerPaint == null) {
mDividerPaint = new Paint();
}
mDividerPaint.setColor(color);
}
super.setCacheColorHint(color);
}
下の
/**
* SparseBooleanArrays map integers to booleans. Unlike a normal array of booleans there can be gaps in the indices.
* It is intended to be more efficient than using a HashMap to map Integers to Booleans.
* Integer Boolean , SparseBooleanArrays HashMap .
*/
private SparseBooleanArray mCheckStates;
private LongSparseArray<Boolean> mCheckedIdStates;
public void setChoiceMode(int choiceMode) {
mChoiceMode = choiceMode;
if (mChoiceMode != CHOICE_MODE_NONE) {
if (mCheckStates == null) {
mCheckStates = new SparseBooleanArray();
}
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
mCheckedIdStates = new LongSparseArray<Boolean>();
}
}
}