Methods Summary |
---|
public android.view.View | convertView(int position, android.view.View convertView, android.view.ViewGroup parent)Convert a non-null view.
return ListItemFactory.convertText(convertView, getValueAtPosition(position), position);
|
protected android.widget.ListView | createListView()
return new ListView(this);
|
protected android.util.ListScenario$Params | createParams()
return new Params();
|
protected android.view.View | createView(int position, android.view.ViewGroup parent, int desiredHeight)Create a view for a list item. Override this to create a custom view beyond
the simple focusable / unfocusable text view.
return ListItemFactory.text(position, parent.getContext(), getValueAtPosition(position),
desiredHeight);
|
public void | enableLongPress()Attaches a long press listener. You can find out which views were clicked by calling
{@link #getLongClickedPosition()}.
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView parent, View v, int position, long id) {
positionLongClicked(position);
return true;
}
});
|
public int | getClickedPosition()
return mClickedPosition;
|
public int | getConvertMisses()
return mConvertMisses;
|
public final java.lang.String | getHeaderValue()
if (!mIncludeHeader) {
throw new IllegalArgumentException("no header above list");
}
return mHeaderTextView.getText().toString();
|
public int | getHeightForPosition(int position)
int desiredHeight = (int) (mScreenHeight * mItemScreenSizeFactor);
if (mOverrideItemScreenSizeFactors.containsKey(position)) {
desiredHeight = (int) (mScreenHeight * mOverrideItemScreenSizeFactors.get(position));
}
return desiredHeight;
|
public int | getItemViewType(int position)Return an item type for the specified position in the adapter. Override if your
adapter creates more than one type.
return 0;
|
public android.widget.ListView | getListView()
return mListView;
|
protected android.widget.LinearLayout | getListViewContainer()Returns the LinearLayout containing the ListView in this scenario.
return mLinearLayout;
|
public int | getLongClickedPosition()
return mLongClickedPosition;
|
protected int | getScreenHeight()
return mScreenHeight;
|
public final java.lang.String | getValueAtPosition(int position)
return isItemAtPositionSelectable(position)
?
"position " + position:
"------- " + position;
|
public int | getViewTypeCount()Return the number of types created by the adapter. Override if your
adapter creates more than one type.
return 1;
|
protected abstract void | init(android.util.ListScenario$Params params)How each scenario customizes its behavior.
|
private boolean | isItemAtPositionSelectable(int position)Return whether the item at position is selectable (i.e is a separator).
(external users can access this info using the adapter)
return !mUnselectableItems.contains(position);
|
protected void | nothingSelected()Override this if you want to know that nothing is selected.
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
// for test stability, turn off title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
mScreenHeight = getWindowManager().getDefaultDisplay().getHeight();
final Params params = createParams();
init(params);
readAndValidateParams(params);
mListView = createListView();
mListView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mListView.setDrawSelectorOnTop(false);
for (int i=0; i<mHeaderViewCount; i++) {
TextView header = mHeadersFocusable ?
new EditText(this) :
new TextView(this);
header.setText("Header: " + i);
mListView.addHeaderView(header);
}
for (int i=0; i<mFooterViewCount; i++) {
TextView header = new TextView(this);
header.setText("Footer: " + i);
mListView.addFooterView(header);
}
if (params.mConnectAdapter) {
setAdapter(mListView);
}
mListView.setItemsCanFocus(mItemsFocusable);
if (mStartingSelectionPosition >= 0) {
mListView.setSelection(mStartingSelectionPosition);
}
mListView.setPadding(0, 0, 0, 0);
mListView.setStackFromBottom(mStackFromBottom);
mListView.setDivider(null);
mListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView parent, View v, int position, long id) {
positionSelected(position);
}
public void onNothingSelected(AdapterView parent) {
nothingSelected();
}
});
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
positionClicked(position);
}
});
// set the fading edge length porportionally to the screen
// height for test stability
if (params.mFadingEdgeScreenSizeFactor != null) {
mListView.setFadingEdgeLength((int) (params.mFadingEdgeScreenSizeFactor * mScreenHeight));
} else {
mListView.setFadingEdgeLength((int) ((64.0 / 480) * mScreenHeight));
}
if (mIncludeHeader) {
mLinearLayout = new LinearLayout(this);
mHeaderTextView = new TextView(this);
mHeaderTextView.setText("hi");
mHeaderTextView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
mLinearLayout.addView(mHeaderTextView);
mLinearLayout.setOrientation(LinearLayout.VERTICAL);
mLinearLayout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mListView.setLayoutParams((new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
0,
1f)));
mLinearLayout.addView(mListView);
setContentView(mLinearLayout);
} else {
mLinearLayout = new LinearLayout(this);
mLinearLayout.setOrientation(LinearLayout.VERTICAL);
mLinearLayout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mListView.setLayoutParams((new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
0,
1f)));
mLinearLayout.addView(mListView);
setContentView(mLinearLayout);
}
|
protected void | positionClicked(int position)Override this if you want to know when something has been clicked (perhaps
more importantly, that {@link android.widget.AdapterView.OnItemClickListener} has
been triggered).
setClickedPosition(position);
|
protected void | positionLongClicked(int position)Override this if you want to know when something has been long clicked (perhaps
more importantly, that {@link android.widget.AdapterView.OnItemLongClickListener} has
been triggered).
setLongClickedPosition(position);
|
protected void | positionSelected(int positon)Override this if you want to know when something has been selected (perhaps
more importantly, that {@link android.widget.AdapterView.OnItemSelectedListener} has
been triggered).
|
protected void | readAndValidateParams(android.util.ListScenario$Params params)Read in and validate all of the params passed in by the scenario.
if (params.mMustFillScreen ) {
double totalFactor = 0.0;
for (int i = 0; i < params.mNumItems; i++) {
if (params.mOverrideItemScreenSizeFactors.containsKey(i)) {
totalFactor += params.mOverrideItemScreenSizeFactors.get(i);
} else {
totalFactor += params.mItemScreenSizeFactor;
}
}
if (totalFactor < 1.0) {
throw new IllegalArgumentException("list items must combine to be at least " +
"the height of the screen. this is not the case with " + params.mNumItems
+ " items and " + params.mItemScreenSizeFactor + " screen factor and " +
"screen height of " + mScreenHeight);
}
}
mNumItems = params.mNumItems;
mItemsFocusable = params.mItemsFocusable;
mStartingSelectionPosition = params.mStartingSelectionPosition;
mItemScreenSizeFactor = params.mItemScreenSizeFactor;
mOverrideItemScreenSizeFactors.putAll(params.mOverrideItemScreenSizeFactors);
mUnselectableItems.addAll(params.mUnselectableItems);
mIncludeHeader = params.mIncludeHeader;
mStackFromBottom = params.mStackFromBottom;
mHeaderViewCount = params.mHeaderViewCount;
mHeadersFocusable = params.mHeaderFocusable;
mFooterViewCount = params.mFooterViewCount;
|
public void | requestRectangleOnScreen(int childIndex, android.graphics.Rect rect)Have a child of the list view call {@link View#requestRectangleOnScreen(android.graphics.Rect)}.
final View child = getListView().getChildAt(childIndex);
child.post(new Runnable() {
public void run() {
child.requestRectangleOnScreen(rect);
}
});
|
protected void | setAdapter(android.widget.ListView listView)Sets an adapter on a ListView.
listView.setAdapter(new MyAdapter());
|
public void | setClickedPosition(int clickedPosition)
mClickedPosition = clickedPosition;
|
protected final void | setHeaderValue(java.lang.String value)
if (!mIncludeHeader) {
throw new IllegalArgumentException("no header above list");
}
mHeaderTextView.setText(value);
|
public void | setLongClickedPosition(int longClickedPosition)
mLongClickedPosition = longClickedPosition;
|