List of usage examples for android.widget ListAdapter getItemId
long getItemId(int position);
From source file:com.huewu.pla.lib.internal.PLAListView.java
/** * Returns the set of checked items ids. The result is only valid if the * choice mode has not been set to {@link #CHOICE_MODE_NONE}. * /*from w ww .j a va 2s . c o m*/ * @return A new array which contains the id of each checked item in the * list. * * @deprecated Use {@link #getCheckedItemIds()} instead. */ @Deprecated public long[] getCheckItemIds() { // Use new behavior that correctly handles stable ID mapping. if (mAdapter != null && mAdapter.hasStableIds()) return getCheckedItemIds(); // Old behavior was buggy, but would sort of work for adapters without // stable IDs. // Fall back to it to support legacy apps. if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { final SparseBooleanArray states = mCheckStates; final int count = states.size(); final long[] ids = new long[count]; final ListAdapter adapter = mAdapter; int checkedCount = 0; for (int i = 0; i < count; i++) { if (states.valueAt(i)) { ids[checkedCount++] = adapter.getItemId(states.keyAt(i)); } } // Trim array if needed. mCheckStates may contain false values // resulting in checkedCount being smaller than count. if (checkedCount == count) return ids; else { final long[] result = new long[checkedCount]; System.arraycopy(ids, 0, result, 0, checkedCount); return result; } } return new long[0]; }
From source file:caesar.feng.framework.widget.StaggeredGrid.ExtendableListView.java
/** * Remember enough information to restore the screen state when the data has * changed./*from w w w .jav a 2 s . c o m*/ */ void rememberSyncState() { if (getChildCount() > 0) { mNeedSync = true; mSyncHeight = getHeight(); // Sync the based on the offset of the first view View v = getChildAt(0); ListAdapter adapter = getAdapter(); if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) { mSyncRowId = adapter.getItemId(mFirstPosition); } else { mSyncRowId = NO_ID; } if (v != null) { mSpecificTop = v.getTop(); } mSyncPosition = mFirstPosition; } }
From source file:com.dishes.views.stageredggridview.StaggeredGridView.java
public long getItemIdAtPosition(int position) { ListAdapter adapter = getAdapter(); return (adapter == null || position < 0) ? INVALID_ROW_ID : adapter.getItemId(position); }
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }/*from w w w.j a va 2 s . c o m*/ builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:org.bangbang.support.v4.widget.HListView.java
/** * Returns the set of checked items ids. The result is only valid if * the choice mode has not been set to {@link #CHOICE_MODE_SINGLE}. */* www.j av a2s . com*/ * @return A new array which contains the id of each checked item in the list. */ public long[] getCheckItemIds() { if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { final SparseBooleanArray states = mCheckStates; final int count = states.size(); final long[] ids = new long[count]; final ListAdapter adapter = mAdapter; for (int i = 0; i < count; i++) { ids[i] = adapter.getItemId(states.keyAt(i)); } return ids; } return new long[0]; }
From source file:com.appunite.list.HorizontalListView.java
/** * Returns the set of checked items ids. The result is only valid if the * choice mode has not been set to {@link #CHOICE_MODE_NONE}. * //w ww. j a va 2 s . c om * @return A new array which contains the id of each checked item in the * list. * * @deprecated Use {@link #getCheckedItemIds()} instead. */ @Deprecated public long[] getCheckItemIds() { // Use new behavior that correctly handles stable ID mapping. if (mAdapter != null && mAdapter.hasStableIds()) { return getCheckedItemIds(); } // Old behavior was buggy, but would sort of work for adapters without stable IDs. // Fall back to it to support legacy apps. if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { final SparseBooleanArray states = mCheckStates; final int count = states.size(); final long[] ids = new long[count]; final ListAdapter adapter = mAdapter; int checkedCount = 0; for (int i = 0; i < count; i++) { if (states.valueAt(i)) { ids[checkedCount++] = adapter.getItemId(states.keyAt(i)); } } // Trim array if needed. mCheckStates may contain false values // resulting in checkedCount being smaller than count. if (checkedCount == count) { return ids; } else { final long[] result = new long[checkedCount]; System.arraycopy(ids, 0, result, 0, checkedCount); return result; } } return new long[0]; }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
/** * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to * {@link #CHOICE_MODE_NONE}./*from w w w . j a v a 2s. com*/ * * @return A new array which contains the id of each checked item in the list. * * @deprecated Use {@link #getCheckedItemIds()} instead. */ @Deprecated public long[] getCheckItemIds() { // Use new behavior that correctly handles stable ID mapping. if (mAdapter != null && mAdapter.hasStableIds()) { return getCheckedItemIds(); } // Old behavior was buggy, but would sort of work for adapters without stable IDs. // Fall back to it to support legacy apps. if (mChoiceMode != AbsListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { final SparseArrayCompat<Boolean> states = mCheckStates; final int count = states.size(); final long[] ids = new long[count]; final ListAdapter adapter = mAdapter; int checkedCount = 0; for (int i = 0; i < count; i++) { if (states.valueAt(i)) { ids[checkedCount++] = adapter.getItemId(states.keyAt(i)); } } // Trim array if needed. mCheckStates may contain false values // resulting in checkedCount being smaller than count. if (checkedCount == count) { return ids; } else { final long[] result = new long[checkedCount]; System.arraycopy(ids, 0, result, 0, checkedCount); return result; } } return new long[0]; }
From source file:com.awrtechnologies.valor.valorfireplace.hlistview.widget.HListView.java
/** * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to * {@link #CHOICE_MODE_NONE}./* ww w . j a va 2 s. c o m*/ * * @return A new array which contains the id of each checked item in the list. * * @deprecated Use {@link #getCheckedItemIds()} instead. */ @Deprecated public long[] getCheckItemIds() { // Use new behavior that correctly handles stable ID mapping. if (mAdapter != null && mAdapter.hasStableIds()) { return getCheckedItemIds(); } // Old behavior was buggy, but would sort of work for adapters without stable IDs. // Fall back to it to support legacy apps. if (mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { final SparseArrayCompat<Boolean> states = mCheckStates; final int count = states.size(); final long[] ids = new long[count]; final ListAdapter adapter = mAdapter; int checkedCount = 0; for (int i = 0; i < count; i++) { if (states.valueAt(i)) { ids[checkedCount++] = adapter.getItemId(states.keyAt(i)); } } // Trim array if needed. mCheckStates may contain false values // resulting in checkedCount being smaller than count. if (checkedCount == count) { return ids; } else { final long[] result = new long[checkedCount]; System.arraycopy(ids, 0, result, 0, checkedCount); return result; } } return new long[0]; }
From source file:com.datarita.ultimatecamera.turu.views.TwoWayView.java
private int findSyncPosition() { int itemCount = mItemCount; if (itemCount == 0) { return INVALID_POSITION; }/*from www . ja v a2s. c o m*/ final long idToMatch = mSyncRowId; // If there isn't a selection don't hunt for it if (idToMatch == INVALID_ROW_ID) { return INVALID_POSITION; } // Pin seed to reasonable values int seed = mSyncPosition; seed = Math.max(0, seed); seed = Math.min(itemCount - 1, seed); long endTime = SystemClock.uptimeMillis() + SYNC_MAX_DURATION_MILLIS; long rowId; // first position scanned so far int first = seed; // last position scanned so far int last = seed; // True if we should move down on the next iteration boolean next = false; // True when we have looked at the first item in the data boolean hitFirst; // True when we have looked at the last item in the data boolean hitLast; // Get the item ID locally (instead of getItemIdAtPosition), so // we need the mAdapter final ListAdapter adapter = mAdapter; if (adapter == null) { return INVALID_POSITION; } while (SystemClock.uptimeMillis() <= endTime) { rowId = adapter.getItemId(seed); if (rowId == idToMatch) { // Found it! return seed; } hitLast = (last == itemCount - 1); hitFirst = (first == 0); if (hitLast && hitFirst) { // Looked at everything break; } if (hitFirst || (next && !hitLast)) { // Either we hit the top, or we are trying to move down last++; seed = last; // Try going up next time next = false; } else if (hitLast || (!next && !hitFirst)) { // Either we hit the bottom, or we are trying to move up first--; seed = first; // Try going down next time next = true; } } return INVALID_POSITION; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void rememberSyncState() { if (getChildCount() == 0) { return;/*from www . j av a2 s . co m*/ } mNeedSync = true; if (mSelectedPosition >= 0) { View child = getChildAt(mSelectedPosition - mFirstPosition); mSyncRowId = mNextSelectedRowId; mSyncPosition = mNextSelectedPosition; if (child != null) { mSpecificStart = (mIsVertical ? child.getTop() : child.getLeft()); } mSyncMode = SYNC_SELECTED_POSITION; } else { // Sync the based on the offset of the first view View child = getChildAt(0); ListAdapter adapter = getAdapter(); if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) { mSyncRowId = adapter.getItemId(mFirstPosition); } else { mSyncRowId = NO_ID; } mSyncPosition = mFirstPosition; if (child != null) { mSpecificStart = (mIsVertical ? child.getTop() : child.getLeft()); } mSyncMode = SYNC_FIRST_POSITION; } }