public void loadNextFiveTransactions() { index = lv_Transactions.getFirstVisiblePosition(); View v = lv_Transactions.getChildAt(0); top = (v == null) ? 0 : v.getTop(); FINAL += 5; if (FINAL > listOfAllTransactions.size()) { FINAL = listOfAllTransactions.size(); savingsAccountTransactionsListAdapter = new SavingsAccountTransactionsListAdapter( getActivity(), listOfAllTransactions.subList(INITIAL, FINAL)); savingsAccountTransactionsListAdapter.notifyDataSetChanged(); lv_Transactions.setAdapter(savingsAccountTransactionsListAdapter); lv_Transactions.setSelectionFromTop(index, top); return; } savingsAccountTransactionsListAdapter = new SavingsAccountTransactionsListAdapter( getActivity(), listOfAllTransactions.subList(INITIAL, FINAL)); savingsAccountTransactionsListAdapter.notifyDataSetChanged(); lv_Transactions.setAdapter(savingsAccountTransactionsListAdapter); lv_Transactions.setSelectionFromTop(index, top); }
@Override public void refreshData() { int onLoadDataCount = addData(); if (onLoadDataCount > 0) { mAdapter.notifyDataSetChanged(); singleChatLv.setSelectionFromTop( onLoadDataCount + 1, listViewHeadView.getHeight() + mmPullDownView.getTopViewHeight()); } else { singleChatLv.setSelectionFromTop(1, mmPullDownView.getTopViewHeight()); } }
/** * Pushes data into list adapter. * * @param data the data to push */ @UiThread protected void updateListView(PaginatedList<Artist> data) { if (loadingProgressBar.getVisibility() == View.VISIBLE) loadingProgressBar.setVisibility(View.INVISIBLE); if (data.getCount() <= 0) { Toast.makeText(this, "No singer was found", Toast.LENGTH_LONG).show(); this.finish(); return; } if (artistsFound == null) artistsFound = new PaginatedList<Artist>(data); else artistsFound.addItems(data.getItems()); list = (ListView) findViewById(android.R.id.list); // If the adapter doesn't exist, we create one with the initial data. // If it exists, we update it. int currentPosition = -1; if (adapter == null) { adapter = new ArtistsListAdapter(this, data.getItems()); } else { currentPosition = list.getFirstVisiblePosition(); adapter.addItems(data.getItems()); } list.setAdapter(adapter); list.setSelectionFromTop(currentPosition + 1, 0); if (artistsFound.getPaging().isLast()) list.removeFooterView(loadMoreProgress); this.isLoading = false; }
@Override public boolean scrollToStart() { mListView.setSelectionFromTop(0, 0); // mListView.stopScroll(); setControlVisible(true); return true; }
private void restoreCurrentPosition() { if (todoList != null) { todoList.setSelectionFromTop(todoListIndex, todoListTop); } if (DEBUG) Log.println( Constants.LOGD, TAG, "Set list view to position " + todoListIndex + ", " + todoListTop); }
@Override public void adjustScroll(int scrollHeight, int headerHeight) { if (mListView == null) return; if (scrollHeight == 0 && mListView.getFirstVisiblePosition() >= 1) { return; } mListView.setSelectionFromTop(1, scrollHeight); }
private void onDrawerAnimationEnd(boolean opened) { startedTracking = false; currentAnimation = null; drawerOpened = opened; if (!opened) { if (drawerLayout instanceof ListView) { ((ListView) drawerLayout).setSelectionFromTop(0, 0); } } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_LISTVIEW_TO_TOP: // if add or update the new AR, set ListView to the top lvAr.setSelectionFromTop(0, 0); break; default: AdLoggerUtils.printFromTag("pj", "undefined msg:" + msg.what); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (position == 2) { if (convertView == null) { convertView = inflater.inflate(R.layout.drawer_separator, null); } } else { if (convertView == null || convertView.getId() != position) { convertView = inflater.inflate(R.layout.drawer_row, null); if (convertView != null) { TextView textView = (TextView) convertView; convertView.setId(position); textView.setText(stringArray[position]); textView.setCompoundDrawablesWithIntrinsicBounds( drawableArray[position], null, null, null); } } if (convertView != null) { TextView textView = (TextView) convertView; Typeface roboto = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Medium.ttf"); textView.setTypeface(roboto); if (position == selectedItem) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = getContext().getTheme(); theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); int primaryDark = typedValue.data; ((ListView) parent).setSelectionFromTop(position, convertView.getTop()); textView.setTextColor(primaryDark); textView.getCompoundDrawables()[0].setColorFilter(primaryDark, PorterDuff.Mode.SRC_IN); TypedValue backgroundValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.galleryItemBackground, backgroundValue, true); convertView.setBackgroundColor(backgroundValue.data); } else { TypedValue colorValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.textColorPrimary, colorValue, true); textView.setTextColor(colorValue.data); convertView.setBackgroundColor(Color.TRANSPARENT); textView.getCompoundDrawables()[0].clearColorFilter(); } } else return null; } return convertView; }
private void expand(TOCItem item) { if (item == null) return; item.setExpanded(true); // expand all parents for (TOCItem p = item.getParent(); p != null; p = p.getParent()) p.setExpanded(true); initItems(); refreshList(); if (mItems.size() > 0) { if (item.getGlobalIndex() >= 0) { mListView.setSelection(item.getGlobalIndex()); mListView.setSelectionFromTop(item.getGlobalIndex(), mListView.getHeight() / 2); } else mListView.setSelection(0); } }
/** * 检查是否选择最后2项,是就往上移 * * @param position */ public void checkSelectLastOne(int position) { int selectPosition = 0; if (mLastVisiablePos - 1 == position) { selectPosition = position - mLength + 2; } if (mLastVisiablePos - 2 == position) { selectPosition = position - mLength + 3; } if (selectPosition > 0) { int moveHeight = (int) MyGesture.this.getResources().getDimension(R.dimen.gesture_select_last_move_height); mGestureListView.setSelectionFromTop(selectPosition, moveHeight); } }
public void refreshContent(boolean force) { if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_EDIT || force) { updateListAdapter(); } else if (visibleType == DashboardType.CONFIGURE_MAP) { int index = listView.getFirstVisiblePosition(); View v = listView.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop()); updateListAdapter(); listView.setSelectionFromTop(index, top); } else { listAdapter.notifyDataSetChanged(); } }
@Override public boolean onBackPressed() { if (history.size() > 0) { HistoryEntry he = history.remove(history.size() - 1); actionBar.setTitle(he.title); if (he.dir != null) { listFiles(he.dir); } else { listRoots(); } listView.setSelectionFromTop(he.scrollItem, he.scrollOffset); return false; } return super.onBackPressed(); }
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = getSharedPreferences("PrettyGoodMusicPlayer", MODE_PRIVATE); prefs.edit(); File bestGuessMusicDir = Utils.getBestGuessMusicDirectory(); String prefDir = prefs.getString("ARTIST_DIRECTORY", bestGuessMusicDir.getAbsolutePath()); ListView lv = (ListView) findViewById(R.id.artistListView); if (!prefDir.equals(baseDir)) { baseDir = prefDir; populateArtists(baseDir); simpleAdpt = new SimpleAdapter( this, artists, R.layout.pgmp_list_item_directory, new String[] {"artist"}, new int[] {R.id.PGMPListItemText}); lv.setAdapter(simpleAdpt); } int top = prefs.getInt("ARTIST_LIST_TOP", Integer.MIN_VALUE); int index = prefs.getInt("ARTIST_LIST_INDEX", Integer.MIN_VALUE); if (top > Integer.MIN_VALUE && index > Integer.MIN_VALUE) { Log.i(TAG, "Setting position from saved preferences"); lv.setSelectionFromTop(index, top); } else { Log.i(TAG, "No saved position found"); } SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String theme = sharedPref.getString("pref_theme", getString(R.string.light)); String size = sharedPref.getString("pref_text_size", getString(R.string.medium)); Log.i(TAG, "got configured theme " + theme); Log.i(TAG, "Got configured size " + size); if (currentTheme == null) { currentTheme = theme; } if (currentSize == null) { currentSize = size; } if (!currentTheme.equals(theme) || !currentSize.equals(size)) { finish(); startActivity(getIntent()); } }
@Override public void setSelectionFromTop(int position, int offset) { if (!isCalledFromSuper()) { if (adapter == null) { positionToSetWhenAdapterIsReady = position; offsetToSetWhenAdapterIsReady = offset; return; } if (areHeadersSticky) { if (frame != null && frame.hasHeader()) { offset += frame.getHeaderHeight(); } } position = adapter.translateAdapterPosition(position); } super.setSelectionFromTop(position, offset); }
public void createLobby(JSONArray result) { listOfRooms = new ArrayList<>(); roomIds = new HashMap<>(); try { for (int i = 0; i < result.length(); i++) { JSONObject newRoom = result.getJSONObject(i); LobbyListItem item = new LobbyListItem( newRoom.getString("name"), newRoom.getString("ownerName"), newRoom.getInt("owner"), newRoom.getInt("maxPlayers"), newRoom.getInt("playerCount"), (newRoom.getInt("canBreakWall") == 1), newRoom.getInt("timeLimit"), newRoom.getDouble("maxDist")); listOfRooms.add(item); roomIds.put(newRoom.getString("name"), newRoom.getInt("id")); if (gameToJoin == newRoom.getInt("id")) { joinGame(item); gameToJoin = -1; // Reset gameToJoin so when we return to lobby we don't join it again } } } catch (JSONException e) { e.printStackTrace(); } ListView lobbyList = (ListView) findViewById(R.id.mainList); // Store the scroll position View view = lobbyList.getChildAt(0); int indexPosition = lobbyList.getFirstVisiblePosition(); int top = (view == null) ? 0 : (view.getTop() - lobbyList.getPaddingTop()); lobbyList.setClickable(true); LobbyCustomAdapter adapter = new LobbyCustomAdapter(this, listOfRooms); lobbyList.setAdapter(adapter); // Reset the scroll position lobbyList.setSelectionFromTop(indexPosition, top); }
void updateAdapter(SimpleGraphObjectCursor<T> data) { if (adapter != null) { // As we fetch additional results and add them to the table, we do not // want the items displayed jumping around seemingly at random, frustrating the user's // attempts at scrolling, etc. Since results may be added anywhere in // the table, we choose to try to keep the first visible row in a fixed // position (from the user's perspective). We try to keep it positioned at // the same offset from the top of the screen so adding new items seems // smoother, as opposed to having it "snap" to a multiple of row height // We use the second row, to give context above and below it and avoid // cases where the first row is only barely visible, thus providing little context. // The exception is where the very first row is visible, in which case we use that. View view = listView.getChildAt(1); int anchorPosition = listView.getFirstVisiblePosition(); if (anchorPosition > 0) { anchorPosition++; } GraphObjectAdapter.SectionAndItem<T> anchorItem = adapter.getSectionAndItem(anchorPosition); final int top = (view != null && anchorItem.getType() != GraphObjectAdapter.SectionAndItem.Type.ACTIVITY_CIRCLE) ? view.getTop() : 0; // Now actually add the results. boolean dataChanged = adapter.changeCursor(data); if (view != null && anchorItem != null) { // Put the item back in the same spot it was. final int newPositionOfItem = adapter.getPosition(anchorItem.sectionKey, anchorItem.graphObject); if (newPositionOfItem != -1) { listView.setSelectionFromTop(newPositionOfItem, top); } } if (dataChanged && onDataChangedListener != null) { onDataChangedListener.onDataChanged(PickerFragment.this); } } }
@Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { Log.d(LOG_TAG, "Finishing loader: " + cursor.getCount()); if (cursor.getCount() != 0) { callback.updateProgressIndicator(false); } mCustomAdapter.swapCursor(cursor); // Restore list ot position int listPosition = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getInt(KEY_LIST_FIRST_VISIBLE_POSITION, 0); int listTopPosition = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getInt(KEY_LIST_TOP_POSITION, 0); if (listPosition > 0) { mList.setSelectionFromTop(listPosition, listTopPosition); } }
private void refreshListAllView(String dateSort) { log.debug("refreshListAllView:" + dateSort); Control control = ControlHelper.getControlContent(this, currentFontSize, currentBgColor, topicCurPage); // init get Item All to ArList allLocalList = mDbFeedAdapter.getItems( Constants.MAX_ITEMS, "FAV_BY_FEED_TYPE_NO_DUP", dateSort, null, feedType, null); log.debug("allLocalList Size:" + allLocalList.size()); arrayItemAdapter = new FeedMainItemAdapter(this, R.id.title, allLocalList, control); localViewList.setAdapter(arrayItemAdapter); // restore scroll popsition if (listViewIndex != 0 && listViewTop != 0) { localViewList.setSelectionFromTop(listViewIndex, listViewTop); } }
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final ListView listView = getListView(); listView.setDividerHeight(0); final SwipeDismissListViewTouchListener swipeDismissListener; swipeDismissListener = createSwipeDismissListener(listView); listView.setOnTouchListener(swipeDismissListener); listView.setOnScrollListener(swipeDismissListener.makeScrollListener()); if (!listAdapter.onRestoreInstanceState(savedInstanceState)) { listAdapter.loadContents(activity); } if (savedInstanceState != null) { final int firstPosition = savedInstanceState.getInt(KEY_STATE_FIRST_POS, 0); final int top = savedInstanceState.getInt(KEY_STATE_TOP, 0); listView.setSelectionFromTop(firstPosition, top); } }
public void scrollToTop() { lvTweets.setSelectionFromTop(0, 0); }
@Override public void setSelection(int position, int index) { if (listView != null && listView.getCount() > position && position >= 0) { listView.setSelectionFromTop(position, index); } }
private void Update() { flUpdate = true; try { if (MetersInfo != null) { int SaveIndex = lvMeters.getFirstVisiblePosition(); View V = lvMeters.getChildAt(0); int SaveTop = (V == null) ? 0 : V.getTop(); // . String[] lvItems = new String[MetersInfo.length]; for (int I = 0; I < MetersInfo.length; I++) { lvItems[I] = MetersInfo[I].Descriptor.Name; if (MetersInfo[I].Descriptor.Info.length() > 0) lvItems[I] += " " + "/" + MetersInfo[I].Descriptor.Info + "/"; switch (MetersInfo[I].Status) { case TSensorMeter.STATUS_ERROR: lvItems[I] += " " + "[" + TSensorMeter.STATUS_GetString(MetersInfo[I].Status, this) + ((MetersInfo[I].StatusString != null) ? (", " + MetersInfo[I].StatusString) : "") + "]"; break; // . > case TSensorMeter.STATUS_NOTRUNNING: break; // . > case TSensorMeter.STATUS_RUNNING: lvItems[I] += " " + "[" + TSensorMeter.STATUS_GetString(MetersInfo[I].Status, this) + ((MetersInfo[I].StatusTimestamp > 0.0) ? (" " + Integer.toString( (int) ((OleDate.UTCCurrentTimestamp() - MetersInfo[I].StatusTimestamp) * 24.0 * 60.0)) + " min") : "") + "]"; break; // . > } } ArrayAdapter<String> lvItemsAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_multiple_choice, lvItems); lvMeters.setAdapter(lvItemsAdapter); // . switch (Mode) { case MODE_NORMAL: for (int I = 0; I < MetersInfo.length; I++) lvMeters.setItemChecked(I, MetersInfo[I].flActive); break; // . > case MODE_SELECTOR: if (IDs != null) { for (int I = 0; I < MetersInfo.length; I++) for (int J = 0; J < IDs.length; J++) if (MetersInfo[I].Descriptor.ID.equals(IDs[J])) { lvMeters.setItemChecked(I, true); // . break; // . > } // . IDs = null; } break; // . > } // . lvMeters.setSelectionFromTop(SaveIndex, SaveTop); } else { lvMeters.setAdapter(null); } } finally { flUpdate = false; } }