Search in sources :

Example 1 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project MultiType by drakeet.

the class MultiSelectActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_multi_select);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
    final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return (items.get(position) instanceof Category) ? SPAN_COUNT : 1;
        }
    });
    selectedSet = new TreeSet<>();
    recyclerView.setLayoutManager(layoutManager);
    adapter = new MultiTypeAdapter();
    adapter.applyGlobalMultiTypePool();
    adapter.register(Square.class, new SquareViewBinder(selectedSet));
    loadData();
    assertAllRegistered(adapter, items);
    recyclerView.setAdapter(adapter);
    setupFAB();
}
Also used : Category(me.drakeet.multitype.sample.common.Category) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 2 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project UltimateAndroid by cymcsg.

the class ItemSelectionSupport method setItemChecked.

/**
     * Sets the checked state of the specified position. The is only valid if
     * the choice mode has been set to {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#SINGLE} or
     * {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#MULTIPLE}.
     *
     * @param position The item whose checked state is to be checked
     * @param checked The new checked state for the item
     */
public void setItemChecked(int position, boolean checked) {
    if (mChoiceMode == ChoiceMode.NONE) {
        return;
    }
    final Adapter adapter = mRecyclerView.getAdapter();
    if (mChoiceMode == ChoiceMode.MULTIPLE) {
        boolean oldValue = mCheckedStates.get(position);
        mCheckedStates.put(position, checked);
        if (mCheckedIdStates != null && adapter.hasStableIds()) {
            if (checked) {
                mCheckedIdStates.put(adapter.getItemId(position), position);
            } else {
                mCheckedIdStates.delete(adapter.getItemId(position));
            }
        }
        if (oldValue != checked) {
            if (checked) {
                mCheckedCount++;
            } else {
                mCheckedCount--;
            }
        }
    } else {
        boolean updateIds = mCheckedIdStates != null && adapter.hasStableIds();
        // selected item
        if (checked || isItemChecked(position)) {
            mCheckedStates.clear();
            if (updateIds) {
                mCheckedIdStates.clear();
            }
        }
        // we ensure length of mCheckStates is 1, a fact getCheckedItemPosition relies on
        if (checked) {
            mCheckedStates.put(position, true);
            if (updateIds) {
                mCheckedIdStates.put(adapter.getItemId(position), position);
            }
            mCheckedCount = 1;
        } else if (mCheckedStates.size() == 0 || !mCheckedStates.valueAt(0)) {
            mCheckedCount = 0;
        }
    }
    updateOnScreenCheckedViews();
}
Also used : Adapter(android.support.v7.widget.RecyclerView.Adapter)

Example 3 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project UltimateAndroid by cymcsg.

the class ItemSelectionSupport method onAdapterDataChanged.

public void onAdapterDataChanged() {
    final Adapter adapter = mRecyclerView.getAdapter();
    if (mChoiceMode == ChoiceMode.NONE || adapter == null || !adapter.hasStableIds()) {
        return;
    }
    final int itemCount = adapter.getItemCount();
    // Clear out the positional check states, we'll rebuild it below from IDs.
    mCheckedStates.clear();
    for (int checkedIndex = 0; checkedIndex < mCheckedIdStates.size(); checkedIndex++) {
        final long currentId = mCheckedIdStates.keyAt(checkedIndex);
        final int currentPosition = mCheckedIdStates.valueAt(checkedIndex);
        final long newPositionId = adapter.getItemId(currentPosition);
        if (currentId != newPositionId) {
            // Look around to see if the ID is nearby. If not, uncheck it.
            final int start = Math.max(0, currentPosition - CHECK_POSITION_SEARCH_DISTANCE);
            final int end = Math.min(currentPosition + CHECK_POSITION_SEARCH_DISTANCE, itemCount);
            boolean found = false;
            for (int searchPos = start; searchPos < end; searchPos++) {
                final long searchId = adapter.getItemId(searchPos);
                if (currentId == searchId) {
                    found = true;
                    mCheckedStates.put(searchPos, true);
                    mCheckedIdStates.setValueAt(checkedIndex, searchPos);
                    break;
                }
            }
            if (!found) {
                mCheckedIdStates.delete(currentId);
                mCheckedCount--;
                checkedIndex--;
            }
        } else {
            mCheckedStates.put(currentPosition, true);
        }
    }
}
Also used : Adapter(android.support.v7.widget.RecyclerView.Adapter)

Example 4 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project UltimateAndroid by cymcsg.

the class TwoWayLayoutManager method handleUpdate.

private void handleUpdate() {
    // Refresh state by requesting layout without changing the
    // first visible position. This will ensure the layout will
    // sync with the adapter changes.
    final int firstPosition = getFirstVisiblePosition();
    final View firstChild = findViewByPosition(firstPosition);
    if (firstChild != null) {
        setPendingScrollPositionWithOffset(firstPosition, getChildStart(firstChild));
    } else {
        setPendingScrollPositionWithOffset(RecyclerView.NO_POSITION, 0);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 5 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setLayoutManager(new LinearLayoutManager(this));
    adapter = new IconicAdapter();
    setAdapter(adapter);
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)688 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)612 View (android.view.View)593 TextView (android.widget.TextView)245 ArrayList (java.util.ArrayList)179 Intent (android.content.Intent)148 ImageView (android.widget.ImageView)132 Toolbar (android.support.v7.widget.Toolbar)118 GridLayoutManager (android.support.v7.widget.GridLayoutManager)111 AdapterView (android.widget.AdapterView)109 ViewGroup (android.view.ViewGroup)97 AlertDialog (android.support.v7.app.AlertDialog)91 Bundle (android.os.Bundle)85 ListView (android.widget.ListView)85 BindView (butterknife.BindView)85 Nullable (android.support.annotation.Nullable)78 DialogInterface (android.content.DialogInterface)71 Context (android.content.Context)65 ArrayAdapter (android.widget.ArrayAdapter)65 LayoutInflater (android.view.LayoutInflater)64