List of usage examples for android.widget ListView setOnScrollListener
public void setOnScrollListener(OnScrollListener l)
From source file:org.mozilla.search.PreSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { final View mainView = inflater.inflate(R.layout.search_fragment_pre_search, container, false); // Initialize listview. listView = (ListView) mainView.findViewById(R.id.list_view); listView.setAdapter(cursorAdapter);/*from w ww . ja va 2s. c o m*/ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final String query = getQueryAtPosition(position); if (!TextUtils.isEmpty(query)) { final Rect startBounds = new Rect(); view.getGlobalVisibleRect(startBounds); Telemetry.sendUIEvent(TelemetryContract.Event.SEARCH, TelemetryContract.Method.HOMESCREEN, "history"); searchListener.onSearch(query, new SuggestionAnimation() { @Override public Rect getStartBounds() { return startBounds; } }); } } }); // Create a ListView-specific touch listener. ListViews are given special treatment because // by default they handle touches for their list items... i.e. they're in charge of drawing // the pressed state (the list selector), handling list item clicks, etc. final SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView, new OnDismissCallback() { @Override public void onDismiss(ListView listView, final int position) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { final String query = getQueryAtPosition(position); final int deleted = getActivity().getContentResolver().delete( SearchHistory.CONTENT_URI, SearchHistory.QUERY + " = ?", new String[] { query }); if (deleted < 1) { Log.w(LOG_TAG, "Search query not deleted: " + query); } return null; } }.execute(); } }); listView.setOnTouchListener(touchListener); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. listView.setOnScrollListener(touchListener.makeScrollListener()); // Setting this recycler listener is required to make sure animated views are reset. listView.setRecyclerListener(touchListener.makeRecyclerListener()); return mainView; }
From source file:de.skubware.opentraining.activity.start_training.FExDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_fex_detail, container, false); // show the current exercise ImageView imageview = (ImageView) rootView.findViewById(R.id.imageview); // set gesture detector this.mGestureScanner = new GestureDetector(this.getActivity(), new ExerciseDetailOnGestureListener(this, imageview, mExercise)); // Images//from w ww . j av a 2 s .com if (!mExercise.getImagePaths().isEmpty()) { DataHelper data = new DataHelper(getActivity()); imageview.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString())); } else { imageview.setImageResource(R.drawable.ic_launcher); } imageview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return mGestureScanner.onTouchEvent(event); } }); // set adapter ListView listView = (ListView) rootView.findViewById(R.id.list); final TrainingEntryListAdapter mAdapter = new TrainingEntryListAdapter( (SherlockFragmentActivity) getActivity(), mExercise, mTrainingEntry); listView.setAdapter(mAdapter); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView, new SwipeDismissListViewTouchListener.OnDismissCallback() { @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { mAdapter.remove(position); } mAdapter.notifyDataSetChanged(); } }); listView.setOnTouchListener(touchListener); // Setting this scroll listener is required to ensure that during // ListView scrolling, // we don't look for swipes. listView.setOnScrollListener(touchListener.makeScrollListener()); return rootView; }
From source file:com.learn.mobile.customview.DSwipeRefreshLayout.java
private void initTarget() { if (mTarget instanceof RecyclerView) { RecyclerView recyclerView = (RecyclerView) mTarget; recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override//from w w w. ja va 2 s . c o m public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (!bEnableLoadMore) { return; } if (dy < 0) { return; } if (bLoadMoreProcessing == true) { return; } if (!canLoadMore) { return; } LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); int visibleItemCount = recyclerView.getChildCount(); int totalItemCount = linearLayoutManager.getItemCount(); int firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition(); if ((visibleItemCount + firstVisibleItem) >= totalItemCount) { onLoadMore(); } } }); } else if (mTarget instanceof ListView) { ListView listView = (ListView) mTarget; listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (!bEnableLoadMore) { return; } if (bLoadMoreProcessing == true) { return; } if (!canLoadMore) { return; } ListView listView1 = (ListView) mTarget; if (listView1.getAdapter() == null) { stopLoadMore(); return; } if (listView1.getAdapter().getCount() == 0) { stopLoadMore(); return; } int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount) { onLoadMore(); } else { stopLoadMore(); return; } } }); } }
From source file:de.damdi.fitness.activity.start_training.FExDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_fex_detail, container, false); // show the current exercise ImageView imageview = (ImageView) rootView.findViewById(R.id.imageview); // set gesture detector this.mGestureScanner = new GestureDetector(this.getActivity(), new ExerciseDetailOnGestureListener(this, imageview, mExercise)); // Images/*www . j ava2 s. c om*/ if (!mExercise.getImagePaths().isEmpty()) { DataHelper data = new DataHelper(getActivity()); imageview.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString())); } else { imageview.setImageResource(R.drawable.ic_launcher); } imageview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return mGestureScanner.onTouchEvent(event); } }); // set adapter ListView listView = (ListView) rootView.findViewById(R.id.list); final TrainingEntryListAdapter mAdapter = new TrainingEntryListAdapter((FragmentActivity) getActivity(), mExercise, mTrainingEntry); listView.setAdapter(mAdapter); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView, new SwipeDismissListViewTouchListener.OnDismissCallback() { @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { mAdapter.remove(position); } mAdapter.notifyDataSetChanged(); } }); listView.setOnTouchListener(touchListener); // Setting this scroll listener is required to ensure that during // ListView scrolling, // we don't look for swipes. listView.setOnScrollListener(touchListener.makeScrollListener()); return rootView; }
From source file:me.zhang.accountbook.ui.LicenseFragment.java
private void initUI(View rootView) { ListView licenseList = (ListView) rootView.findViewById(R.id.license_list); // String[]?ArrayList? Collections.addAll(mObjects, getResources().getStringArray(R.array.licenses)); adapter = new ArrayAdapter<>(getActivity(), R.layout.list_item_license, mObjects); licenseList.setAdapter(adapter);//from ww w .j a v a 2 s .co m // ?? licenseList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO ??, ? } }); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(licenseList, new SwipeDismissListViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { adapter.remove(adapter.getItem(position)); } } }); licenseList.setOnTouchListener(touchListener); licenseList.setOnScrollListener(touchListener.makeScrollListener()); }
From source file:org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.audio_albums_songs, container, false); ListView albumsList = (ListView) v.findViewById(R.id.albums); ListView songsList = (ListView) v.findViewById(R.id.songs); List<View> lists = Arrays.asList((View) albumsList, songsList); String[] titles = new String[] { getString(R.string.albums), getString(R.string.songs) }; mViewPager = (ViewPager) v.findViewById(R.id.pager); mViewPager.setOffscreenPageLimit(MODE_TOTAL - 1); mViewPager.setAdapter(new AudioPagerAdapter(lists, titles)); mViewPager.setOnTouchListener(mSwipeFilter); TabLayout mTabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs); mTabLayout.setupWithViewPager(mViewPager); songsList.setAdapter(mSongsAdapter); albumsList.setAdapter(mAlbumsAdapter); songsList.setOnItemClickListener(songsListener); albumsList.setOnItemClickListener(albumsListener); registerForContextMenu(albumsList);/*from w w w . ja v a 2 s . co m*/ registerForContextMenu(songsList); mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeLayout); mSwipeRefreshLayout.setColorSchemeResources(R.color.orange700); mSwipeRefreshLayout.setOnRefreshListener(this); songsList.setOnScrollListener(mScrollListener); albumsList.setOnScrollListener(mScrollListener); getActivity().setTitle(mTitle); return v; }
From source file:com.mobicage.rogerthat.plugins.friends.ServiceSearchActivity.java
private BroadcastReceiver getBroadCastReceiver() { return new SafeBroadcastReceiver() { @Override/*from w w w. ja v a 2 s.c o m*/ public String[] onSafeReceive(Context context, Intent intent) { String action = intent.getAction(); if (mSearchString != null && FriendsPlugin.SERVICE_SEARCH_RESULT_INTENT.equals(action)) { if (mSearchString.equals(intent.getStringExtra(SEARCH_STRING))) { mProgressDialog.dismiss(); String jsonResult = intent.getStringExtra(SEARCH_RESULT); @SuppressWarnings("unchecked") Map<String, Object> jsonMap = (Map<String, Object>) JSONValue.parse(jsonResult); try { mResponseTO = new FindServiceResponseTO(jsonMap); } catch (IncompleteMessageException e) { L.bug(e); showSearchFailedDialog(); return new String[] { action }; } if (!TextUtils.isEmptyOrWhitespace(mResponseTO.error_string)) { UIUtils.showAlertDialog(ServiceSearchActivity.this, null, mResponseTO.error_string); return new String[] { action }; } for (FindServiceCategoryTO category : mResponseTO.matches) { if (mSearchInfoByCategory.containsKey(category.category)) { SearchInfo si = mSearchInfoByCategory.get(category.category); si.cursor = category.cursor; si.loading = false; si.adapter.addAll(category.items); } else { // Add Label LinearLayout label = (LinearLayout) getLayoutInflater() .inflate(R.layout.search_category, null); final boolean selected = mSearchCategoryLabels.getChildCount() == 0; final TextView labelTextView = setCatorySelected(label, selected); labelTextView.setText(category.category); label.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { displayTab(mSearchCategoryLabels.indexOfChild(v)); } }); mSearchCategoryLabels.addView(label); // Add ListView ListView results = (ListView) getLayoutInflater() .inflate(R.layout.search_category_results, null); mSearchCategoryViewFlipper.addView(results); SearchInfo si = new SearchInfo(); ServiceSearchAdapter adapter = new ServiceSearchAdapter(category.items, si); si.cursor = category.cursor; si.adapter = adapter; si.label = label; si.results = results; mSearchInfoByCategory.put(category.category, si); mSearchInfoByListView.put(results, si); results.setAdapter(adapter); results.setOnItemClickListener(mListItemClickListener); results.setOnScrollListener(mListViewScrollListener); } } return new String[] { action }; } } else if (FriendsPlugin.SERVICE_SEARCH_FAILED_INTENT.equals(action)) { if (mSearchString.equals(intent.getStringExtra(SEARCH_STRING))) { mProgressDialog.dismiss(); showSearchFailedDialog(); return new String[] { action }; } } else { L.d(ServiceSearchActivity.class.getName() + " received " + action + " intent"); for (SearchInfo si : mSearchInfoByCategory.values()) { si.adapter.notifyDataSetChanged(); } // not interested in older intents which also result in reloading the list return UPDATE_VIEW_INTENTS; } return null; } }; }
From source file:com.google.samples.apps.sergio.ui.BaseActivity.java
protected void enableActionBarAutoHide(final ListView listView) { initActionBarAutoHide();/*from w w w. ja va 2s .c o m*/ listView.setOnScrollListener(new AbsListView.OnScrollListener() { final static int ITEMS_THRESHOLD = 3; int lastFvi = 0; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { onMainContentScrolled(firstVisibleItem <= ITEMS_THRESHOLD ? 0 : Integer.MAX_VALUE, lastFvi - firstVisibleItem > 0 ? Integer.MIN_VALUE : lastFvi == firstVisibleItem ? 0 : Integer.MAX_VALUE); lastFvi = firstVisibleItem; } }); }
From source file:com.google.samples.apps.iosched.ui.BaseActivity.java
protected void enableActionBarAutoHide(final ListView listView) { initActionBarAutoHide();/*from w ww . j av a 2 s .c o m*/ listView.setOnScrollListener(new AbsListView.OnScrollListener() { /** The heights of all items. */ private Map<Integer, Integer> heights = new HashMap<>(); private int lastCurrentScrollY = 0; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Get the first visible item's view. View firstVisibleItemView = view.getChildAt(0); if (firstVisibleItemView == null) { return; } // Save the height of the visible item. heights.put(firstVisibleItem, firstVisibleItemView.getHeight()); // Calculate the height of all previous (hidden) items. int previousItemsHeight = 0; for (int i = 0; i < firstVisibleItem; i++) { previousItemsHeight += heights.get(i) != null ? heights.get(i) : 0; } int currentScrollY = previousItemsHeight - firstVisibleItemView.getTop() + view.getPaddingTop(); onMainContentScrolled(currentScrollY, currentScrollY - lastCurrentScrollY); lastCurrentScrollY = currentScrollY; } }); }
From source file:org.physical_web.physicalweb.NearbyBeaconsFragment.java
private void initialize(View rootView) { setHasOptionsMenu(true);// w w w . ja v a 2s. c o m mGroupIdQueue = new ArrayList<>(); mHandler = new Handler(); mSwipeRefreshWidget = (SwipeRefreshWidget) rootView.findViewById(R.id.swipe_refresh_widget); mSwipeRefreshWidget.setColorSchemeResources(R.color.swipe_refresh_widget_first_color, R.color.swipe_refresh_widget_second_color); mSwipeRefreshWidget.setOnRefreshListener(this); getActivity().getActionBar().setTitle(R.string.title_nearby_beacons); mNearbyDeviceAdapter = new NearbyBeaconsAdapter(); setListAdapter(mNearbyDeviceAdapter); //Get the top drawable mScanningAnimationTextView = (TextView) rootView.findViewById(android.R.id.empty); mScanningAnimationDrawable = (AnimationDrawable) mScanningAnimationTextView.getCompoundDrawables()[1]; ListView listView = (ListView) rootView.findViewById(android.R.id.list); mDiscoveryServiceConnection = new DiscoveryServiceConnection(); mWifiDirectConnect = new WifiDirectConnect(getActivity()); mBluetoothSite = new BluetoothSite(getActivity()); mTouchListener = new SwipeDismissListViewTouchListener(listView, new SwipeDismissListViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(ListView listView, int position) { Utils.addBlocked(mNearbyDeviceAdapter.getItem(position)); Utils.saveBlocked(getActivity()); if (mMissedEmptyGroupIdQueue) { mMissedEmptyGroupIdQueue = false; emptyGroupIdQueue(); } } }); listView.setOnTouchListener(mTouchListener); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. listView.setOnScrollListener(mTouchListener.makeScrollListener()); Utils.restoreFavorites(getActivity()); Utils.restoreBlocked(getActivity()); }