Git Product home page Git Product logo

sectionedrecyclerviewadapter's People

Contributors

dreamersoul avatar friederbluemle avatar jub-jan avatar luizgrp avatar philipp91 avatar yccheok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sectionedrecyclerviewadapter's Issues

Getting adapter position sometimes produces IndexOutOfBoundsException

How do you implement a click listener on an adapter if am wrong? I implemented SectionedGridview, it works superb even the search funtionality except the clicklistener, here is how I made mine

holder.btn_option.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View v) {
onItemClickedListener.onItemClicked(v, holder.getAdapterPosition());
}
});

where the onItemClickedListener is basically an interface, I get wrong positions

NoClassDefFoundError after adding the library

I had a "Caused by: java.lang.NoClassDefFoundError: android.support.design.internal.NavigationMenuPresenter" after adding the lib "compile 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.0.4'"

Is it a known issue?

Horizontal Scroll possible?

How to make horizontal Scrollable ??i tried making Linear LAyout Manager as Horizontal.It doesnot look good

FastScroller?

Does anyone know of a fast scroller implementation that works with this library? The current fast scroller implementation I was using no longer works now that I am using this sectioning technique with the RecyclerView.

not really an issue more like a concern

hey this is not really an issue more like a concern.. what are the chances that you stop updating this library in the future i dont want to use it and then it breaks later down the road

Notify content changed in section with header

Hello!
I've tried to update/insert section with header after setting adapter to recycler view.

Here is my code:

adapter = new SectionedRecyclerViewAdapter();
rvContacts.setAdapter(adapter);

and then

ContactCardSection section = new ContactCardSection(title, contactList);
adapter.addSection(section);
adapter.notifyDataSetChanged();

But only header has been updated.
How to update content in this case?

Divider drawn between items in StatelessSection

I'm adding a seperator to my RecyclerView with this code:

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
    layoutManager.getOrientation());
recyclerView.addItemDecoration(dividerItemDecoration);

However, the divider is also drawn between items in a section. You can see this in the screenshot (I changed the color to red for better visibility). Dividers should only be visible above "TechRabbit" and "Amazon.com".
screenshot_20161223-102857

I'm happy to help with this, if you tell me how it can be fixed.

Disable touch on "section"

Hello, I was testing this lib and I found out that "section" is clicked like any normal item. How can I prevent "section" from triggering the click event. And how can I add a custom long press event in the section?

Thanks in advanced, great work!

wrong section TAG value

Hi there ,

I'm try to remove some rows from section one and some from section two , but

                            sectionAdapter.notifyItemRemovedFromSection(TAG, key);

TAG always return the section list string title , but i was selected row in first list

here is full class code 👍

  class ContactsSection extends StatelessSection {

    final String TAG;
    String title;
    List<Item> list;
    ItemViewHolder row;
    HeaderViewHolder MainRow;

    ContactsSection(String title, ArrayList<Item> list) {
        super(R.layout.shopping_row_item_header, R.layout.shopping_row_item);
        this.title = title;
        this.list = list;
        this.TAG = title;
    }

    @Override
    public int getContentItemsTotal() {
        return list.size();
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(View view) {
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(final RecyclerView.ViewHolder holder, final int position) {

        final ItemViewHolder itemHolder = (ItemViewHolder) holder;
        final Item name = list.get(position);
        itemHolder.tvItem.setText(name.name);
        ((ItemViewHolder) holder).IntegBOX.setChecked(name.checked);
        ((ItemViewHolder) holder).IntegBOX.setTag(position);


        deleteAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

                Iterator it = selectedCheckBox.entrySet().iterator();
                if (!it.hasNext()) {

                    new makeDialog().makeDialog(mActivity, mActivity.getResources().getString(R.string.share_no_data));

                } else {

          
                    while (it.hasNext()) {
                        Map.Entry pair = (Map.Entry) it.next();
                        int key = (Integer) pair.getKey();
                        if ((Boolean) pair.getValue()) {
                            list.remove(key);

 // problem Here 
                            sectionAdapter.notifyItemRemovedFromSection(TAG, key);               

 }
             

                    }

                    chooseAllradioButton.setSelected(false);
                }
            }
        });


        itemHolder.IntegBOX.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Set the button's appearance
                ((CheckBox) v).setChecked(!((CheckBox) v).isChecked());

                // if button Already in checked statue
                if (((CheckBox) v).isChecked()) {

                    Iterator it = selectedCheckBox.entrySet().iterator();
                    while (it.hasNext()) {
                        Map.Entry pair = (Map.Entry) it.next();
                        int key = (Integer) pair.getKey();
                        if (key == (Integer) v.getTag()) {
                            it.remove();
                        }
                        // set it as false
                        ((CheckBox) v).setChecked(false);
                    }
                } else {
                    // Otherwise set it to true and add it to hashMap
                    ((CheckBox) v).setChecked(true);
                    selectedCheckBox.put((Integer) v.getTag(), true);
                }


                Toast.makeText(mActivity, String.format("Clicked on position #%s of Section %s", sectionAdapter.getPositionInSection(itemHolder.getAdapterPosition()), title), Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return new HeaderViewHolder(view);
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
        HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
        headerHolder.tvTitle.setText(title);
    }

    // Remove All Btn Fuc





    class HeaderViewHolder extends RecyclerView.ViewHolder {

        private final TextView tvTitle;

        HeaderViewHolder(View view) {
            super(view);
            tvTitle = (TextView) view.findViewById(R.id.DishName);
        }
    }

    class ItemViewHolder extends RecyclerView.ViewHolder implements CompoundButton.OnCheckedChangeListener {

        private final View rootView;
        private final TextView tvItem;
        private final CheckBox IntegBOX;

        ItemViewHolder(View view) {
            super(view);

            rootView = view;
            tvItem = (TextView) view.findViewById(R.id.DishName);
            IntegBOX = (CheckBox) view.findViewById(R.id.chooseDish);
            IntegBOX.setOnCheckedChangeListener(this);
        }

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            //   int position = getAdapterPosition();
            //   list.get(position).checked = isChecked;
        }
    }


}


private class Item {
    String name;
    boolean checked;

    Item(String name) {
        this.name = name;
        checked = false;
    }
}

add sections code :

 for (int d = 0; d < DishesIngredientsShoppingList.size(); d++) {
        contacts = new ArrayList<>();
        for (int i = 0; i < DishesIngredientsShoppingList.get(d).getGroups().length; i++) {
            for (int g = 0; g < DishesIngredientsShoppingList.get(d).getGroups()[i].getIngredients().length; g++) {
                if (Language)
                    contacts.add(new Item(DishesIngredientsShoppingList.get(d).getGroups()[i].getIngredients()[g].getName()));
                else
                    contacts.add(new Item(DishesIngredientsShoppingList.get(d).getGroups()[i].getIngredients()[g].getNameEnglish()));


            }
        }

     sectionAdapter = new SectionedRecyclerViewAdapter();
    ArrayList<Item> contacts = new ArrayList<>();
    // ArrayList<String> dishNames = new ArrayList<>();
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
             if (Language)
            sectionAdapter.addSection(DishesIngredientsShoppingList.get(d).getName(), new ContactsSection(DishesIngredientsShoppingList.get(d).getName(),contacts));
        else
            sectionAdapter.addSection(DishesIngredientsShoppingList.get(d).getEnglishName(), new ContactsSection(DishesIngredientsShoppingList.get(d).getEnglishName(),contacts));


    }
    mRecyclerView.setAdapter(sectionAdapter);

Is it possible to have EMPTY in Section class

Currently, in Section class, we have

public enum State { LOADING, LOADED, FAILED}

Is it possible to support

public enum State { LOADING, LOADED, FAILED, EMPTY}

This is because sometimes, the data within a section is empty, we need to show different UI.

Thanks for the very thoughtful library. It saves developers a lot of time.

How can I call notifyItemChanged from within StatelessSection?

Hi,

First of all thanks for the section recycler view adapter it works very well.

We are now trying to implement swipe to delete feature and I am struggling in figuring out how we can call notifyItemChangedInSection from within our custom class which extends the StatelessSection?

Thanks in advance.

Error during build

After including the gradle reference to an existing app, the build is throwing the following error:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/application_name) from AndroidManifest.xml:46:9-49
    is also present at [io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.0.4] AndroidManifest.xml:11:18-50 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:41:5-428:19 to override.

Adding the suggested override helps but is this really necessary?

Change State of Section using notifyItemChangedInSection will cause unwanted animation

Currently, if I change the Section's State via

// Current State is FAILED.        
watchlistSection.setState(Section.State.LOADING);
sectionAdapter.notifyItemChangedInSection(watchlistSection, 0);

It will cause unwanted animation. Although I had tried to turn off animation via

RecyclerView.ItemAnimator itemAnimator = this.recyclerView.getItemAnimator();
if (itemAnimator instanceof SimpleItemAnimator) {
    ((SimpleItemAnimator)itemAnimator).setSupportsChangeAnimations(false);
}

It doesn't help much. As you can see in the video, when the View changed from

a sad cloud face to progress bar

, there's unwanted flickering effect.

https://youtu.be/x-X-SXs0Acc - Using setSupportsChangeAnimations(false)

Note, if I use the following code, there's still a unwanted flickering effect. But, this time, the flickering effect is different from previous

RecyclerView.ItemAnimator itemAnimator = this.recyclerView.getItemAnimator();
if (itemAnimator instanceof SimpleItemAnimator) {
    ((SimpleItemAnimator)itemAnimator).setSupportsChangeAnimations(true);
}

https://youtu.be/m4jLfhUpjQc - setSupportsChangeAnimations(true)

I can completely eliminated the unwanted flickering effect, by removing SimpleItemAnimation. However, this will cause other problem. Some, some item in the recycler view, I need to perform swipe-to-delete and drag-n-move UX effect. Without SimpleItemAnimation, I can't achieve such effect.

this.recyclerView.setItemAnimator(null);

https://youtu.be/MyZlqPCeS7s - this.recyclerView.setItemAnimator(null)

Any idea how I can avoid unwanted animation/ flickering effect during notifyItemChangedInSection, without removing SimpleItemAnimation? I expect setSupportsChangeAnimations(false) will work, but it doesn't.

Support for searchview

Hi,
nice work with your adapter , light and easy to use , that's pretty rare ;)

Is there any searchview support available ? If no, should i just extends SectionedRecyclerViewAdapter to implement it ?
I currently have a searchable adapter (implemented following this : http://stackoverflow.com/a/30429439/393984) but it need sections :)

Global status

Is it possible to implement a global state?

    SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();
    // set default state
    sectionAdapter.setState(State.LOADING)
    // create AsyncTask
    AsyncTask task = new MyAsyncTask();
    task.execute()
    ...

    public class MyAsynkTask extends AsyncTask<String, Void, Map<String, List<String>>> {

        @Override
        protected Map<String, List<String>> doInBackground(String... params) {
            Map<String, List<String>> result = new HashMap<>();
            List<String> list = new ArrayList<>();
            // load html document and parse
            list.add("message");
            result.put("m", list);
            return result;
        }

        @Override
        protected void onPostExecute(Map<String, List<String>> stringListMap) {
            // create StatelessSection
            for (Map.Entry<String, List<String>> entry : stringListMap.entrySet()) {
                sectionAdapter.addSection(new MySection(entry.getKey(), entry.getValue()));
            }
            sectionAdapter.setState(Section.State.LOADED);
        }
    }

And new state "Empty".

Why is gradle complaining about not finding appcompat-v7.jar?

so I'm adding the library as a depency like this:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    ...
    compile 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.0.4'
}

But when trying to sync the project with Gradle, I get this:

Warning:Module 'com.android.support:appcompat-v7:24.1.1' depends on one or more Android Libraries but is a jar
Error:A problem occurred configuring project ':app'.
> Could not find appcompat-v7.jar (com.android.support:appcompat-v7:24.1.1).
  Searched in the following locations:
      https://jcenter.bintray.com/com/android/support/appcompat-v7/24.1.1/appcompat-v7-24.1.1.jar

I know that the problem is caused by the library, because when I delete that line the project syncs successfully.

This is the full app/build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.boel.demorv"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    compile 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.0.4'
}

So, why is gradle complaining about not finding appcompat-v7.jar in https://jcenter.bintray.com/com/android/support/appcompat-v7/24.1.1/appcompat-v7-24.1.1.jar?

Thanks in advance! I really want to use this library.

Some questions regarding onCreateViewHolder

In onCreateViewHolder, I realize after

Section section = sections.get(entry.getKey());

There's isn't any need to check, whether section is visible or not. Does it mean, section is surely always visible?

The reason I have concern in onCreateViewHolder is that, currently, I have a Section. which whenever I set it to FAILED state, I will always hide it.

if (portfolioSection.getState() == Section.State.LOADING) {
    portfolioSection.setState(Section.State.FAILED);

    hideSection(sectionAdapter, portfolioSection);
}

private hideSection(SectionedRecyclerViewAdapter sectionedRecyclerViewAdapter, Section section) {
    if (false == section.isVisible()) {
        // Already invisible.
        return;
    }

    int sectionPosition = sectionedRecyclerViewAdapter.getSectionPosition(section);

    section.setVisible(false);

    sectionedRecyclerViewAdapter.notifySectionChangedToInvisible(section, sectionPosition);
}

Hence, I'm not exactly sure, whether I should need to provide a dummy view for FAILED state,

or it is OK not providing view for FAILED state, with assumption onCreateViewHolder will not be triggered for this invisible Section?

public class PortfolioSection extends Section {
    public PortfolioSection() {
        super(new SectionParameters.Builder(R.layout.trading_portfolio_item_section)
                .headerResourceId(R.layout.trading_portfolio_header_section)
                .loadingResourceId(R.layout.trading_portfolio_loading_section)
                .failedResourceId(R.layout.dummy_view)
                .build());

or

public class PortfolioSection extends Section {
    public PortfolioSection() {
        super(new SectionParameters.Builder(R.layout.trading_portfolio_item_section)
                .headerResourceId(R.layout.trading_portfolio_header_section)
                .loadingResourceId(R.layout.trading_portfolio_loading_section)
                .build());

I had tested the one without failed resource id. Works fine but I'm not sure whether it is correct, or I had missed out any edge case. Or, should I just provide an empty dummy view just to play safe?

Thanks.

Lazy loading / Pagination

How can we achieve lazy loading or pagination with onScrolllistener in this SectionedRecycler View Adapter. i want to add received items dynamically to any section of the adapter.

How to obtain position the position of the head?

Hi,How can I get the head position location, I need to get the location of the head of each section of the position Then call RecyclerView. SmoothScrollToPosition () to jump to the corresponding position

How to notifyDataSetChanged

After add new partitions and/or add an item to a section I call notifyDataSetChanged but the list is not refreshed. The data definitely change because after rotating the screen displays the updated list.

purchaselistRecyclerView.getAdapter().notifyDataSetChanged();

It find a bug

In Example8Fragment,I change GridLayoutManager like this:
GridLayoutManager glm = new GridLayoutManager(getContext(), 4);
I run it,it looks not what I want.
I dont know why,and how to fix it.
Thank You!

NotifyDataSetChanges is not working and collpase by default.

  1. After calling the notifyItemChanged or DataSetChanged data is still not getting refreshed.
  2. Is there any way I could show all items in collapse state by default and then when user click on individual section header section should expand. I have huge data that I am passing to adapter

Does it make sense to provide notifyItemChangedInHeader and notifyItemChangedInFooter

I was wondering, does it make sense, to provide the following methods

notifyItemChangedInHeader(String TAG)
notifyItemChangedInHeader(Section section)
notifyItemChangedInFooter(String TAG)
notifyItemChangedInFooter(Section section)

Currently, I have the following use case.

small

For the following 3 components, they are belongs to single item in single section

  • price (968.99) as same Item within same Section
  • chart as same Item within same Section
  • buttons (buy & sell) as same Item within same Section

So, whenever there are changes in price or buttons, I need to call notifyItemChangedInItem. However, chart drawing is an expensive activity. Calling notifyItemChangedInItem will cause unnecessary chart re-drawing. My current workaround is to keep a special position flag, to prevent unnecessary chart re-drawing.

My ideal way is to place

  • price (968.99) as Header within same Section
  • chart as Item within same Section
  • buttons (buy & sell) as Footer within same Section

So, whenever there are changes in price or buttons, I just need to call notifyItemChangedInHeader or notifyItemChangedInFooter, without trigger chart as item.

If such changes make sense, I'm more to happy to send another pull request for that.

Thank you.

Does it make sense to provide setItemResourceId for Section class

Currently, I have a use case.

The content of item, will based on network result from server. Its code more or less look as the following.

watchlistSection.setState(Section.State.LOADING);
...
...
// Perform some networking operation, to return user current status.
...
...
watchlistSection.setItemResourceId(getBestItemResourceIdBasedNetworkingOperationResult());
watchlistSection.setState(Section.State.LOADED);

Currently, the only way to provide item resource id for Section, is via constructor. We do not have setItemResourceId.

Does it make sense to add the following code in Section ?

// Section.java
public void setItemResourceId(int itemResourceId) {
    this.itemResourceId = itemResourceId;
}

How to Filter section item listview elements based on Comparator

I have issue in Section Item filtering based on Comparator.

I have used the below code for filtering in section itemview layout. In my code my section item view has an recyclerview with list of elements.

for (Section section : sectionAdapter.getSectionsMap().values()) {

                    if (section instanceof FilterableSection) {
                        ((FilterableSection) section).filteratoz();
                    }
                }
                sectionAdapter.notifyDataSetChanged();  

In my section adapter i have user the below codes
interface FilterableSection {
void filteratoz();
}

public void filteratoz(){
for (Categorysubcatmodel value : filteredList) {
Collections.sort(filteredList, new Comparator() {
public int compare(Categorysubcatmodel v1, Categorysubcatmodel v2) {
return v1.getName().compareTo(v2.getName());
}
});
}
sectionAdapter.notifyDataSetChanged();

    }

filteredList - Array List which has data items in it. If i run the app i have got the below exception:

java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
at com.halal.travel.fragments.Thingsfragment$HeaderRecyclerViewSection1.filteratoz(Thingsfragment.java:1383)
at com.halal.travel.fragments.Thingsfragment$2.onClick(Thingsfragment.java:318)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

Clicking twice for items

I'm not sure if anyone has faced this issue before but the problem that I'm facing is the following:
I have a menu fragment that slides in from the left when a menu buttons is tapped. Inside that menu fragment I have a recyclerview and I feed it as an adapter SectionRecyclerViewAdapter.
Everything works fine but when I scroll to see the not visible items and click on one of the new items, I end up clicking twice to select it. I can reproduce 100% of the time.
I realized that it was always the items that become visible are the ones that I have to click twice and it might be related to the adapter.

Here is what I'm doing in my viewholder:

@Override    
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        final MenuExtrasViewHolder itemHolder = (MenuExtrasViewHolder) holder;

        final MenuExtra extra = extras.getExtra(position);
        itemHolder.setRelativePosition(position);

        setImage(extra, itemHolder);
        setTitle(extra, itemHolder);

        itemHolder.getRootView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick");
                final MenuExtra extra = extras.getExtra(itemHolder.getRelativePosition());

                if (extra.isRateApp()) {
                    rateApp();

                } else if (extra.isShareApp()) {
                    shareApp();
                }

                Analytics.get().logExtras(extra.getTitle());
            }
        });
    }

The log would only show onClick once when the second tap happens. How can I solve this as it is very annoying.

Better support Android Annotations

Hello,

I want to use your library in conjunction with Android Annotations. More specifically, this part: https://github.com/excilys/androidannotations/wiki/Adapters-and-lists

While it will probably work fine already, I would have to inflate the view twice, potentionally wasting memory and resources during app initialization (something I'd like to avoid).

The view would first be inflated in:

view = LayoutInflater.from(parent.getContext()).inflate(section.getItemResourceId(), parent, false);

and then here:

    @Override
    protected PersonItemView onCreateItemView(ViewGroup parent, int viewType) {
        return PersonItemView_.build(context);
    }

If I, somehow, could tell SectionedRecyclerViewAdapter to not call inflate, then everything should work perfectly. E.g. by setting resource ID to -1, or by calling some function assigning a boolean value.

An Error message

after implementing stateless section header;

E/RecyclerView: No adapter attached; skipping layout

  [ 08-03 06:15:12.708    82:   82 D/         ]
   Socket deconnection

Why showing this?

Alternative to sectionAdapter.notifyDataSetChanged

Most of the time, whenever there are background threads performing

  • Change Section state from LOADING to EMPTY
  • Change Section state from LOADED to EMPTY
  • setHasHeader(true)/ setHasHeader(false)
  • section.setVisible(true)/ section.setVisible(false)

I will use sectionAdapter.notifyDataSetChanged, so that visualize effect will take in immediately.

However, when I implement a complex drag-n-drop/ drag-n-move UX in one of the Sections, I wish to avoid using sectionAdapter.notifyDataSetChanged. The reason is that, if other Section threads call sectionAdapter.notifyDataSetChanged, it will break my Watchlist section drag-n-drop/ drag-n-move UX effect.

a

After experimenting, I had came out with the following code to replace sectionAdapter.notifyDataSetChanged

if (orders.isEmpty()) {
    orderSection.setState(Section.State.EMPTY);

    if (orderSection.hasHeader()) {
        int headerPosition = sectionAdapter.getHeaderPositionInAdapter(orderSection);
        orderSection.setHasHeader(false);
        sectionAdapter.notifyItemRemovedFromSection(orderSection, headerPosition);
    }

    // I think this works fine, if it changed from LOADING TO EMPTY. But,
    // what if it changed from LOADED (More than 1 item) to EMPTY? Does the
    // following code still work fine?
    sectionAdapter.notifyItemRangeChangedInSection(
            orderSection,
            0,
            1
    );
} else {
    orderSection.updateOrders(orders);
    if (!orderSection.hasHeader()) {
        orderSection.setHasHeader(true);
        sectionAdapter.notifyHeaderChangedInSection(orderSection);
    }
    
    if (orderSection.getState() != Section.State.LOADED) {
        orderSection.setState(Section.State.LOADED);
    }

    sectionAdapter.notifyItemRangeChangedInSection(
            orderSection,
            0,
            orderSection.getContentItemsTotal()
    );
}
  1. When I hide header, I use notifyItemRemovedFromSection
  2. When I show header, I use notifyHeaderChangedInSection
  3. When I change State from LOADING to EMPTY, I use notifyItemRangeChangedInSection, with item count is 1.
  4. When I change State from X to LOADED, I use notifyItemRangeChangedInSection, with item count is Section.getContentItemsTotal().

Do you think the above is a good way, so that our update operation is capped at Section level, and doesn't spread to other Section?

What other notification way I can use, if I have the following case?

  1. When section.setVisible(true)/ section.setVisible(false)
  2. When I change State from LOADED to EMPTY ?

Thanks.

could i setting StatelessSection ?

hi you project was wonderful,but i need some special
look this image
d06166e5-1640-4816-98c3-7d8d3ee8c85f
for this view i need add two section
SectionedRecyclerViewAdapter.addSection(new AnchorListSection())
SectionedRecyclerViewAdapter.addSection(new LiveListSection())
but the part of 2 i need setting two line so that's the problem
SectionedRecyclerViewAdapter only can setting unitive line
but i need setting the item line
i think StatelessSection should offer some API that i can setting each item line

Scrolling is jerky.

I have added 4 sections and each section has around 4 to 5 items. When I scroll (up and down) list, it jerks. How can I make it scroll smoothly.

Layout for Items section

I want to put items below each header to a CardView. Is it possible? Where should the layouts be replaced?

Thanks.

Set animations

Hi! Great library! I am having trouble adding annimation in item added and removed, any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.