Example usage for android.widget ListView setRecyclerListener

List of usage examples for android.widget ListView setRecyclerListener

Introduction

In this page you can find the example usage for android.widget ListView setRecyclerListener.

Prototype

public void setRecyclerListener(RecyclerListener listener) 

Source Link

Document

Sets the recycler listener to be notified whenever a View is set aside in the recycler for later reuse.

Usage

From source file:org.kontalk.ui.adapter.ContactsListAdapter.java

public ContactsListAdapter(Context context, ListView list) {
    super(context, null, false);
    mFactory = LayoutInflater.from(context);

    list.setRecyclerListener(new RecyclerListener() {
        public void onMovedToScrapHeap(View view) {
            if (view instanceof ContactsListItem) {
                ((ContactsListItem) view).unbind();
            }/*from  ww  w .j a  v  a2s  .  co m*/
        }
    });
}

From source file:org.kontalk.ui.adapter.MessageListAdapter.java

public MessageListAdapter(Context context, Cursor cursor, Pattern highlight, ListView list,
        AudioPlayerControl audioPlayerControl) {
    super(context, cursor, false);
    mFactory = LayoutInflater.from(context);
    mHighlight = highlight;//from  w  ww. j a v  a 2 s.com
    mAudioPlayerControl = audioPlayerControl;

    list.setRecyclerListener(new RecyclerListener() {
        public void onMovedToScrapHeap(View view) {
            if (view instanceof MessageListItem) {
                ((MessageListItem) view).unbind();
            }
        }
    });
}

From source file:com.aboveware.sms.ui.MessageListAdapter.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public MessageListAdapter(Context context, ListView listView, Pattern highlight) {
    super(context, null, 0);
    mContext = context;/*from ww w  .j  a v a 2s  . c o m*/
    mHighlight = highlight;

    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mMessageItemCache = new MessageItemCache(CACHE_SIZE);

    listView.setRecyclerListener(new AbsListView.RecyclerListener() {
        @Override
        public void onMovedToScrapHeap(View view) {
            if (view instanceof MessageListItem) {
                MessageListItem mli = (MessageListItem) view;
                // Clear references to resources
                mli.unbind();
            }
        }
    });
}

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);/*w  w  w.  j  a  va2  s  .  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;
}