use of android.widget.ListAdapter in project android-topeka by googlesamples.
the class SelectItemQuizView method setUserInput.
@Override
public void setUserInput(Bundle savedInput) {
if (savedInput == null) {
return;
}
mAnswers = savedInput.getBooleanArray(KEY_ANSWERS);
if (mAnswers == null) {
return;
}
final ListAdapter adapter = mListView.getAdapter();
for (int i = 0; i < mAnswers.length; i++) {
mListView.performItemClick(mListView.getChildAt(i), i, adapter.getItemId(i));
}
}
use of android.widget.ListAdapter in project material by rey5137.
the class ListPopupWindow method performItemClick.
/**
* Perform an item click operation on the specified list adapter position.
*
* @param position Adapter position for performing the click
* @return true if the click action could be performed, false if not.
* (e.g. if the popup was not showing, this method would return false.)
*/
public boolean performItemClick(int position) {
if (isShowing()) {
if (mItemClickListener != null) {
final DropDownListView list = mDropDownList;
final View child = list.getChildAt(position - list.getFirstVisiblePosition());
final ListAdapter adapter = list.getAdapter();
mItemClickListener.onItemClick(list, child, position, adapter.getItemId(position));
}
return true;
}
return false;
}
use of android.widget.ListAdapter in project material by rey5137.
the class ListPopupWindow method onKeyDown.
/**
* Filter key down events. By forwarding key down events to this function,
* views using non-modal ListPopupWindow can have it handle key selection of items.
*
* @param keyCode keyCode param passed to the host view's onKeyDown
* @param event event param passed to the host view's onKeyDown
* @return true if the event was handled, false if it was ignored.
*
* @see #setModal(boolean)
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
// when the drop down is shown, we drive it directly
if (isShowing()) {
// to select one of its items
if (keyCode != KeyEvent.KEYCODE_SPACE && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) {
int curIndex = mDropDownList.getSelectedItemPosition();
boolean consumed;
final boolean below = !mPopup.isAboveAnchor();
final ListAdapter adapter = mAdapter;
boolean allEnabled;
int firstItem = Integer.MAX_VALUE;
int lastItem = Integer.MIN_VALUE;
if (adapter != null) {
allEnabled = adapter.areAllItemsEnabled();
firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true);
lastItem = allEnabled ? adapter.getCount() - 1 : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
}
if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
// When the selection is at the top, we block the key
// event to prevent focus from moving.
clearListSelection();
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
show();
return true;
} else {
// WARNING: Please read the comment where mListSelectionHidden
// is declared
mDropDownList.mListSelectionHidden = false;
}
consumed = mDropDownList.onKeyDown(keyCode, event);
if (DEBUG)
Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed);
if (consumed) {
// If it handled the key event, then the user is
// navigating in the list, so we should put it in front.
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
// Here's a little trick we need to do to make sure that
// the list view is actually showing its focus indicator,
// by ensuring it has focus and getting its window out
// of touch mode.
mDropDownList.requestFocusFromTouch();
show();
switch(keyCode) {
// next component
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_UP:
return true;
}
} else {
if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
// event to avoid going to the next focusable widget
if (curIndex == lastItem) {
return true;
}
} else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) {
return true;
}
}
}
}
return false;
}
use of android.widget.ListAdapter in project facebook-android-sdk by facebook.
the class FullListView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = 0;
ListAdapter adapter = getAdapter();
int count = adapter != null ? adapter.getCount() : 0;
for (int i = 0; i < count; i++) {
View childView = adapter.getView(i, null, this);
childView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
height += childView.getMeasuredHeight();
}
height += getDividerHeight() * (count - 1);
setMeasuredDimension(width, height);
}
use of android.widget.ListAdapter in project XobotOS by xamarin.
the class ListFragment method ensureList.
private void ensureList() {
if (mList != null) {
return;
}
View root = getView();
if (root == null) {
throw new IllegalStateException("Content view not yet created");
}
if (root instanceof ListView) {
mList = (ListView) root;
} else {
mStandardEmptyView = (TextView) root.findViewById(com.android.internal.R.id.internalEmpty);
if (mStandardEmptyView == null) {
mEmptyView = root.findViewById(android.R.id.empty);
} else {
mStandardEmptyView.setVisibility(View.GONE);
}
mProgressContainer = root.findViewById(com.android.internal.R.id.progressContainer);
mListContainer = root.findViewById(com.android.internal.R.id.listContainer);
View rawListView = root.findViewById(android.R.id.list);
if (!(rawListView instanceof ListView)) {
throw new RuntimeException("Content has view with id attribute 'android.R.id.list' " + "that is not a ListView class");
}
mList = (ListView) rawListView;
if (mList == null) {
throw new RuntimeException("Your content must have a ListView whose id attribute is " + "'android.R.id.list'");
}
if (mEmptyView != null) {
mList.setEmptyView(mEmptyView);
} else if (mEmptyText != null) {
mStandardEmptyView.setText(mEmptyText);
mList.setEmptyView(mStandardEmptyView);
}
}
mListShown = true;
mList.setOnItemClickListener(mOnClickListener);
if (mAdapter != null) {
ListAdapter adapter = mAdapter;
mAdapter = null;
setListAdapter(adapter);
} else {
// have our data right away and start with the progress indicator.
if (mProgressContainer != null) {
setListShown(false, false);
}
}
mHandler.post(mRequestFocus);
}
Aggregations