List of usage examples for android.widget ListView setSelectionFromTop
public void setSelectionFromTop(int position, int y)
From source file:Main.java
/** * Scrolls a specific list view to the item at a specific index. * * @param listView//from w ww . j a v a 2s . c o m * The list view, which should be scrolled, as an instance of the class {@link * ListView}. The list view may not be null * @param index * The index of the item, the list view should be scrolled to, as an {@link Integer} * value * @param offset * The offset of the item, the list view should be scrolled to, as an {@link Integer} * value */ private static void scrollTo(@NonNull final ListView listView, final int index, final int offset) { listView.setSelectionFromTop(index, offset); }
From source file:Main.java
public static void smoothScrollListView(ListView listView, int position, int offset, int duration) { if (VERSION.SDK_INT > 7) { listView.smoothScrollToPositionFromTop(position, offset, duration); }/*from w w w . j a v a2 s .c om*/ else { listView.setSelectionFromTop(position, offset); } }
From source file:com.reallynourl.nourl.fmpfoldermusicplayer.utility.Util.java
/** * Loads the position of the ListView from the Bundle. Make sure you saved if before with * {@link Util#saveScrollPositionToBundle(Bundle, ListView, String)} * This method does nothing if th data couldn't be found. * @param bundle the bundle to load the data from * @param listView the ListView to scroll * @param lvName the name previously used in * {@link Util#saveScrollPositionToBundle(Bundle, ListView, String)} *//*from w ww . j av a2 s . c o m*/ public static void loadScrollPositionFromBundle(Bundle bundle, ListView listView, String lvName) { int scrollIndex = bundle.getInt(lvName + "_scroll_index", Integer.MIN_VALUE); int top = bundle.getInt(lvName + "_top", Integer.MIN_VALUE); if (scrollIndex == Integer.MIN_VALUE || top == Integer.MIN_VALUE) { Log.i(TAG, "Failed to load scroll position from bundle for name: " + lvName); } else { listView.setSelectionFromTop(scrollIndex, top); } }
From source file:com.glanznig.beepme.view.HistoryFragment.java
private void populateList() { BeeperApp app = (BeeperApp) getActivity().getApplication(); List<Bundle> statList = Statistics.getStats(getActivity(), app.getTimerProfile()); HistoryListAdapter historyAdapter = new HistoryListAdapter(getActivity(), statList); setListAdapter(historyAdapter);/*w w w . ja v a 2 s .co m*/ ListView list = (ListView) getView().findViewById(android.R.id.list); list.setSelectionFromTop(position, 0); }
From source file:com.glanznig.beepme.view.SampleListFragment.java
private void populateList() { List<Sample> samplesList = new SampleTable(getActivity().getApplicationContext()).getSamples(); ArrayList<ListItem> viewList = new ArrayList<ListItem>(); Iterator<Sample> i = samplesList.iterator(); DateListSectionHeader header = null; while (i.hasNext()) { Sample s = i.next();//from ww w . j ava 2s . com if (header == null || !header.isSameDay(s.getTimestamp())) { header = new DateListSectionHeader(s.getTimestamp()); viewList.add(header); } viewList.add(new SampleListEntry(s)); } SampleListAdapter samples = new SampleListAdapter(getActivity(), viewList); setListAdapter(samples); ListView list = (ListView) getView().findViewById(android.R.id.list); list.setSelectionFromTop(position, 0); }
From source file:org.nsoft.openbus.adapter.TimelinePagerAdapter.java
@Override public Object instantiateItem(View view, int position) { View myView = childs.get(position).getCollumnView(); try {/*from ww w. j av a 2 s. com*/ ((ViewPager) view).addView(myView); } catch (Exception e) { // TODO: handle exception } ListView listView = childs.get(position).getScrollView(); if (listView != null) { Facade facade = Facade.getInstance(parent.getContext()); CollumnConfig config = facade.getOneConfig(position); try { int top = states.get(position).top; int scrollTo = states.get(position).scrollTo; if (top != 0 && scrollTo != 0) listView.setSelectionFromTop(scrollTo, top); } catch (IndexOutOfBoundsException e) { // TODO: handle exception } } return myView; }
From source file:com.wenhui.syncedListView.lib.SyncedListLayout.java
private void scrollListBy(ListView target, int deltaY) { final int firstPosition = target.getFirstVisiblePosition(); if (firstPosition == ListView.INVALID_POSITION) { return;/* w w w . j a v a 2 s .c o m*/ } final View firstView = target.getChildAt(0); if (firstView == null) { return; } final int newTop = firstView.getTop() - deltaY; target.setSelectionFromTop(firstPosition, newTop); }
From source file:org.kde.kdeconnect.UserInterface.PairingFragment.java
private void updateComputerList() { BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() { @Override//www. j a v a 2s .c om public void onServiceStart(final BackgroundService service) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { if (listRefreshCalledThisFrame) { // This makes sure we don't try to call list.getFirstVisiblePosition() // twice per frame, because the second time the list hasn't been drawn // yet and it would always return 0. return; } listRefreshCalledThisFrame = true; headerText.setText( getString(NetworkHelper.isOnMobileNetwork(getContext()) ? R.string.on_data_message : R.string.pairing_description)); try { Collection<Device> devices = service.getDevices().values(); final ArrayList<ListAdapter.Item> items = new ArrayList<>(); SectionItem section; Resources res = getResources(); section = new SectionItem(res.getString(R.string.category_not_paired_devices)); section.isSectionEmpty = true; items.add(section); for (Device device : devices) { if (device.isReachable() && !device.isPaired()) { items.add(new PairingDeviceItem(device, PairingFragment.this)); section.isSectionEmpty = false; } } section = new SectionItem(res.getString(R.string.category_connected_devices)); section.isSectionEmpty = true; items.add(section); for (Device device : devices) { if (device.isReachable() && device.isPaired()) { items.add(new PairingDeviceItem(device, PairingFragment.this)); section.isSectionEmpty = false; } } if (section.isSectionEmpty) { items.remove(items.size() - 1); //Remove connected devices section if empty } section = new SectionItem(res.getString(R.string.category_remembered_devices)); section.isSectionEmpty = true; items.add(section); for (Device device : devices) { if (!device.isReachable() && device.isPaired()) { items.add(new PairingDeviceItem(device, PairingFragment.this)); section.isSectionEmpty = false; } } if (section.isSectionEmpty) { items.remove(items.size() - 1); //Remove remembered devices section if empty } final ListView list = (ListView) rootView.findViewById(R.id.listView1); //Store current scroll int index = list.getFirstVisiblePosition(); View v = list.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() - list.getPaddingTop()); list.setAdapter(new ListAdapter(mActivity, items)); //Restore scroll list.setSelectionFromTop(index, top); } catch (IllegalStateException e) { e.printStackTrace(); //Ignore: The activity was closed while we were trying to update it } finally { listRefreshCalledThisFrame = false; } } }); } }); }
From source file:com.amaze.filemanager.fragments.AppsList.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true);//w w w . j a v a2 s . com mainActivity = (MainActivity) getActivity(); mainActivity.setActionBarTitle(utils.getString(getActivity(), R.string.apps)); mainActivity.floatingActionButton.hideMenuButton(true); mainActivity.buttonBarFrame.setVisibility(View.GONE); mainActivity.supportInvalidateOptionsMenu(); fabSkin = mainActivity.fabskin; vl = getListView(); Sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); getSortModes(); ListView vl = getListView(); int theme = Integer.parseInt(Sp.getString("theme", "0")); theme1 = theme == 2 ? PreferenceUtils.hourOfDay() : theme; vl.setDivider(null); if (theme1 == 1) getActivity().getWindow().getDecorView() .setBackgroundColor(getResources().getColor(R.color.holo_dark_background)); if (savedInstanceState == null) loadlist(false); else { c = savedInstanceState.getParcelableArrayList("c"); a = savedInstanceState.getParcelableArrayList("list"); adapter = new AppsAdapter(getActivity(), R.layout.rowlayout, a, app, c); setListAdapter(adapter); vl.setSelectionFromTop(savedInstanceState.getInt("index"), savedInstanceState.getInt("top")); } }
From source file:com.igniva.filemanager.fragments.AppsList.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true);/*from w ww. ja va2s .c o m*/ mainActivity = (MainActivity) getActivity(); mainActivity.setActionBarTitle(utils.getString(getActivity(), R.string.apps)); mainActivity.floatingActionButton.hideMenuButton(true); mainActivity.buttonBarFrame.setVisibility(View.GONE); mainActivity.supportInvalidateOptionsMenu(); vl = getListView(); Sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); getSortModes(); ListView vl = getListView(); int theme = Integer.parseInt(Sp.getString("theme", "0")); theme1 = theme == 2 ? PreferenceUtils.hourOfDay() : theme; vl.setDivider(null); if (theme1 == 1) getActivity().getWindow().getDecorView() .setBackgroundColor(getResources().getColor(R.color.holo_dark_background)); if (savedInstanceState == null) loadlist(false); else { c = savedInstanceState.getParcelableArrayList("c"); a = savedInstanceState.getParcelableArrayList("list"); adapter = new AppsAdapter(getActivity(), R.layout.rowlayout, a, app, c); setListAdapter(adapter); vl.setSelectionFromTop(savedInstanceState.getInt("index"), savedInstanceState.getInt("top")); vl.setSelectionFromTop(savedInstanceState.getInt("index"), savedInstanceState.getInt("top")); } setHasOptionsMenu(true); }