List of usage examples for android.widget ListView setOnScrollListener
public void setOnScrollListener(OnScrollListener l)
From source file:net.naonedbus.fragment.CustomListFragment.java
private void setupListView(final LayoutInflater inflater, final View view) { final ListView listView = (ListView) mFragmentView.findViewById(android.R.id.list); listView.setOnScrollListener(new OnScrollListener() { @Override/*from w ww. j a v a 2 s. c o m*/ public void onScrollStateChanged(final AbsListView view, final int scrollState) { } @Override public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, final int totalItemCount) { triggerOnScrollListeners(listView, firstVisibleItem, visibleItemCount, totalItemCount); } }); if (listView instanceof PinnedHeaderListView) { final PinnedHeaderListView pinnedListView = (PinnedHeaderListView) listView; pinnedListView.setPinnedHeaderView(inflater.inflate(mLayoutListHeaderId, pinnedListView, false)); addOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(final AbsListView view, final int scrollState) { } @Override public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, final int totalItemCount) { final Adapter adapter = getListAdapter(); if (adapter != null && adapter instanceof OnScrollListener) { final OnScrollListener sectionAdapter = (OnScrollListener) adapter; sectionAdapter.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } } }); } }
From source file:com.btmura.android.reddit.app.ThingListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) v.findViewById(android.R.id.list); lv.setVerticalScrollBarEnabled(false); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(this); SwipeDismissTouchListener touchListener = new SwipeDismissTouchListener(lv, this); lv.setOnTouchListener(touchListener); ThumbnailLoader.lock(false);/* w w w. j a v a 2 s . c o m*/ final OnScrollListener scrollListener = touchListener.makeScrollListener(); lv.setOnScrollListener(new OnScrollListener() { @Override public void onScroll(AbsListView lv, int firstVisible, int visibleCount, int totalCount) { scrollListener.onScroll(lv, firstVisible, visibleCount, totalCount); ThingListFragment.this.onScroll(lv, firstVisible, visibleCount, totalCount); } @Override public void onScrollStateChanged(AbsListView lv, int scrollState) { scrollListener.onScrollStateChanged(lv, scrollState); ThingListFragment.this.onScrollStateChanged(lv, scrollState); } }); return v; }
From source file:com.othermedia.exampleasyncimage.AsyncImageDemo.java
/** Called when the activity is first created. */ @Override/*from w w w . j a v a2 s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // -- AsyncImage initialization: AsyncImageRegistry.initialize(getApplicationContext()); /* Example of using AsyncImage with a single ImageView * AsyncImageCache defaultCache = AsyncImageRegistry.getInstance().getDefaultCache(); ImageView remotePhoto = new ImageView(getApplicationContext()); this.setContentView(remotePhoto); defaultCache.loadRemoteImage(remotePhoto, // <- target ImageView "http://www.othermedia.com/data/images/originals/office-263.jpg", // <- bitmap URL R.drawable.imageplaceholder); // <- optionally, default resource to show when downloading */ // -- Register a special cache just for our Twitter Avatars with file caching "on" AsyncImageRegistry.getInstance().registerCache(AsyncImageDemo.AVATARS_CACHE, true); // -- Setting up the example: userList = new ArrayList<SampleTweet>(); sampleAdapter = new SampleAdapter(getApplicationContext(), userList); ListView list = new ListView(getApplicationContext()); list.setAdapter(sampleAdapter); setContentView(list); // Get the first portion of Twitter Users talking about Android :) (new TwitterDownloader()).execute(); // -- AsyncImage hook up ListView to the cache (for holding up new downloads - it's optional) // AsyncImageRegistry.getInstance().getRegisteredCache(LOGOS_CACHE).installScrollListnerOn(list); // Or, do it Manually, if you need a custom OnScrollListener list.setOnScrollListener(new OnScrollListener() { // This holds up the Cache's Download Queue public void onScrollStateChanged(AbsListView listView, int scrollState) { if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) AsyncImageRegistry.getInstance().getRegisteredCache(AVATARS_CACHE).holdQueue(); if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) AsyncImageRegistry.getInstance().getRegisteredCache(AVATARS_CACHE).resumeQueue(); } // This loads more items once the ListView reaches the bottom public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem + visibleItemCount == totalItemCount && currentPage < 20 && !downloaderRunning) { currentPage++; (new TwitterDownloader()).execute(); } } }); Toast.makeText(getApplicationContext(), "Loading...", 1000).show(); }
From source file:com.irccloud.android.activity.PastebinsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC));/*from w w w. j av a 2 s . c o m*/ cloud.recycle(); } setContentView(R.layout.ignorelist); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar)); getSupportActionBar().setElevation(0); } if (savedInstanceState != null && savedInstanceState.containsKey("adapter")) { try { page = savedInstanceState.getInt("page"); Pastebin[] pastebins = (Pastebin[]) savedInstanceState.getSerializable("adapter"); for (Pastebin p : pastebins) { adapter.addPastebin(p); } adapter.notifyDataSetChanged(); } catch (Exception e) { page = 0; adapter.clear(); } } footer = getLayoutInflater().inflate(R.layout.messageview_header, null); ListView listView = (ListView) findViewById(android.R.id.list); listView.setAdapter(adapter); listView.addFooterView(footer); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) { canLoadMore = false; new FetchPastebinsTask().execute((Void) null); } } }); listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { final Pastebin p = (Pastebin) adapter.getItem(i); Intent intent = new Intent(PastebinsActivity.this, PastebinViewerActivity.class); intent.setData(Uri.parse(p.url + "?id=" + p.id + "&own_paste=" + (p.own_paste ? "1" : "0"))); startActivity(intent); } }); Toast.makeText(this, "Tap a pastebin to view full text with syntax highlighting", Toast.LENGTH_LONG).show(); }
From source file:com.conferenceengineer.android.iosched.ui.AnnouncementsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final ListView listView = getListView(); if (!UIUtils.isTablet(getActivity())) { view.setBackgroundColor(getResources().getColor(R.color.stream_spacer_color)); }/* w w w . j a va 2 s. co m*/ if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) { int verticalMargin = getResources().getDimensionPixelSize(R.dimen.social_stream_padding_vertical); if (verticalMargin > 0) { listView.setClipToPadding(false); listView.setPadding(0, verticalMargin, 0, verticalMargin); } } listView.setOnScrollListener(this); listView.setDrawSelectorOnTop(true); listView.setDivider(getResources().getDrawable(android.R.color.transparent)); listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.page_margin_width)); TypedValue v = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true); listView.setSelector(v.resourceId); setListAdapter(mStreamAdapter); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.AnnouncementsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final ListView listView = getListView(); if (!UIUtils.isTablet(getActivity())) { view.setBackgroundColor(getResources().getColor(R.color.plus_stream_spacer_color)); }/*from w w w. java 2 s . com*/ if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) { int verticalMargin = getResources().getDimensionPixelSize(R.dimen.plus_stream_padding_vertical); if (verticalMargin > 0) { listView.setClipToPadding(false); listView.setPadding(0, verticalMargin, 0, verticalMargin); } } listView.setOnScrollListener(this); listView.setDrawSelectorOnTop(true); listView.setDivider(getResources().getDrawable(android.R.color.transparent)); listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.page_margin_width)); TypedValue v = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true); listView.setSelector(v.resourceId); setListAdapter(mStreamAdapter); }
From source file:net.abcdroid.devfest12.ui.SocialStreamFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.setBackgroundColor(Color.WHITE); final ListView listView = getListView(); listView.setCacheColorHint(Color.WHITE); listView.setOnScrollListener(this); listView.setDrawSelectorOnTop(true); TypedValue v = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true); listView.setSelector(v.resourceId);// ww w. j av a 2s.c o m }
From source file:com.example.app.tweetui.TimelineActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tweetui_swipe_timeline); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(R.string.refresh_timeline_title); }/*from w ww . jav a 2 s .c o m*/ // launch the app login activity when a guest user tries to favorite a Tweet final Callback<Tweet> actionCallback = new Callback<Tweet>() { @Override public void success(Result<Tweet> result) { // Intentionally blank } @Override public void failure(TwitterException exception) { if (exception instanceof TwitterAuthException) { startActivity(TwitterCoreMainActivity.newIntent(TimelineActivity.this)); } } }; final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); final View emptyView = findViewById(android.R.id.empty); final ListView listView = (ListView) findViewById(android.R.id.list); listView.setEmptyView(emptyView); final SearchTimeline timeline = new SearchTimeline.Builder().query("#twitter").build(); final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this).setTimeline(timeline) .setViewStyle(R.style.tw__TweetLightWithActionsStyle).setOnActionCallback(actionCallback).build(); listView.setAdapter(adapter); swipeLayout.setColorSchemeResources(R.color.twitter_blue, R.color.twitter_dark); // set custom scroll listener to enable swipe refresh layout only when at list top listView.setOnScrollListener(new AbsListView.OnScrollListener() { boolean enableRefresh = false; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (listView != null && listView.getChildCount() > 0) { // check that the first item is visible and that its top matches the parent enableRefresh = listView.getFirstVisiblePosition() == 0 && listView.getChildAt(0).getTop() >= 0; } else { enableRefresh = false; } swipeLayout.setEnabled(enableRefresh); } }); // specify action to take on swipe refresh swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeLayout.setRefreshing(true); adapter.refresh(new Callback<TimelineResult<Tweet>>() { @Override public void success(Result<TimelineResult<Tweet>> result) { swipeLayout.setRefreshing(false); } @Override public void failure(TwitterException exception) { swipeLayout.setRefreshing(false); final Activity activity = activityRef.get(); if (activity != null && !activity.isFinishing()) { Toast.makeText(activity, exception.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } }); }
From source file:au.id.tmm.anewreader.view.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main_activity); ListView feedListView = (ListView) this.findViewById(R.id.drawer_layout_feed_list); this.feedArrayAdapter = new FeedArrayAdapter(this, android.R.layout.simple_list_item_1); feedListView.setAdapter(this.feedArrayAdapter); feedListView.setOnItemClickListener(onFeedListItemClickListener); ListView itemListView = (ListView) this.findViewById(R.id.item_list); this.itemArrayAdapter = new ItemArrayAdapter(this, android.R.layout.simple_list_item_1); itemListView.addFooterView(//from w ww. j ava 2 s.c om this.getLayoutInflater().inflate(R.layout.adapter_view_item_list_loading_footer, null)); itemListView.setAdapter(this.itemArrayAdapter); itemListView.setOnItemClickListener(onItemListItemClickListener); itemListView.setOnScrollListener(onItemListScrollListener); DisplayItems.getInstance().registerListener(this.displayItemsListener); pullToRefreshAttacher = PullToRefreshAttacher.get(this); pullToRefreshAttacher.addRefreshableView(itemListView, this.onPullToRefreshListener); pullToRefreshAttacher.setEnabled(false); this.findViewById(R.id.main_activity_error_panel).setOnClickListener(onErrorPanelClickListener); this.retrieveAccount(); }
From source file:com.WazaBe.GooglePlusStream.SocialStreamFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.setBackgroundColor(Color.WHITE); final ListView listView = getListView(); listView.setCacheColorHint(Color.WHITE); listView.setOnScrollListener(this); listView.setDrawSelectorOnTop(true); // TypedValue v = new TypedValue(); // getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, // v, true);/*from w w w. ja v a2 s . c om*/ // listView.setSelector(v.resourceId); }