Code Monkey home page Code Monkey logo

Comments (5)

ryantanjunming avatar ryantanjunming commented on August 28, 2024 1

I figured out a fix, one is to use BindingAdapters, but expanded acts as an initial attribute and changing it does not trigger the animated drop-down. Its good however for storing the state (e.g. half-read faq)

class ViewModel extends BaseObservable{
    
   @BindingAdapter({"ael_expanded"})
    public static void setExpand(ExpandableRelativeLayout expandableRelativeLayout,
                                 boolean expanded){
        expandableRelativeLayout.setExpanded(expanded);
    }

    public boolean isExpand() {
        return expand;
    }

    public void setExpand(boolean expand) {
        this.expand = expand;
    }

    public View.OnClickListener onReadMoreClick(){
        return new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                setExpand(!isExpand()); //flip
                notifyChange();
            }
        };
    }

My final solution was in my RecycleView.Adapter in the onBindViewHolder class which is found in the git repository sample examples:

public void onBindViewHolder(BindingHolder holder, int position) {
        final ItemArticleBinding binding = holder.binding;
        holder.setIsRecyclable(false);
        binding.setAvm(new ArticlesViewModel(mResult.get(position), mContext));
        binding.itemArticlesExpandLayout.setInRecyclerView(true);
        binding.itemArticlesButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                onClickButton(binding.itemArticlesExpandLayout);
            }
        });
    }

   private void onClickButton(final ExpandableLayout expandableLayout){
        expandableLayout.toggle();
    }

from expandablelayout.

ryantanjunming avatar ryantanjunming commented on August 28, 2024

Did you find a solution?

from expandablelayout.

DOFandersolsen avatar DOFandersolsen commented on August 28, 2024

@natnayr
Hi Ryan,

I never actually got around to finding a solution, so I reworked my layout into another design that didn't have expandable parts.

Thank you for your solution, I'll close the issue but I probably won't be using your code.

from expandablelayout.

hshahdoost avatar hshahdoost commented on August 28, 2024

Isn't it better if the required BindingAdapter was provided by the library itself? it's just a little work, But can be a lot helpful to those who are using data-binding in their project. I suggest you reopen this issue.
One more thing, setting the setExpanded in our BindingAdapter bypasses the animations. I suggest you use the following source to keep the animations while using data-binding.

@BindingAdapter("app:ael_expand")
public static void setExpanded(View v, boolean expanded){
    if(!(v instanceof ExpandableLayout))
        throw new RuntimeException("Invalid attribute, only allowed on ExpandableLayout");

    ExpandableLayout layout = (ExpandableLayout)v;
    if(expanded)
        layout.expand();
    else
        layout.collapse();
}

from expandablelayout.

cloudbank avatar cloudbank commented on August 28, 2024

databinding does not like the underscore in your variable in general. It will not bind a layout if you try to use one in its id for example.

from expandablelayout.

Related Issues (20)

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.