Code Monkey home page Code Monkey logo

Comments (11)

cachapa avatar cachapa commented on July 21, 2024

I'm afraid that's not enough information for me to figure out what the problem is. Can you share the code (layout and related java source)?

Have you tried following the demo example?
https://github.com/cachapa/ExpandableLayout/blob/master/demo/src/main/java/net/cachapa/expandablelayoutdemo/RecyclerViewFragment.java

from expandablelayout.

joaovictortinoco avatar joaovictortinoco commented on July 21, 2024

Ok!

This is my Adapter class:

 package br.com.medflex.adapters;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageButton;
import android.widget.TextView;

import net.cachapa.expandablelayout.ExpandableLayout;

import java.util.List;

import br.com.medflex.R;
import br.com.medflex.utils.MinhaConsulta;

public class MinhaConsultaAdapter extends RecyclerView.Adapter<MinhaConsultaAdapter.ViewHolder> {
    private int UNSELECTED = -1;

    private RecyclerView recyclerView;
    private int selectedItem = UNSELECTED;
    private List<MinhaConsulta> consultas;

    public MinhaConsultaAdapter(RecyclerView recyclerView, List<MinhaConsulta> consultas) {
        this.recyclerView = recyclerView;
        this.consultas = consultas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.expandable_minha_consulta_row, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.bind(position);
    }

    @Override
    public int getItemCount() {
        return consultas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private ExpandableLayout expandableLayout;
        private TextView especialidade, data, hora, local;
        private ImageButton imgExpand;
        private int position;

        public ViewHolder(View itemView) {
            super(itemView);

            expandableLayout = (ExpandableLayout) itemView.findViewById(R.id.expandable_recycler);
            expandableLayout.setInterpolator(new OvershootInterpolator());

            especialidade = (TextView) itemView.findViewById(R.id.txt_consulta_especialidade);
            data = (TextView) itemView.findViewById(R.id.txt_consulta_data);
            especialidade.setOnClickListener(this);
        }

        public void bind(int position) {
            this.position = position;

            especialidade.setSelected(false);
            expandableLayout.collapse(false);

            especialidade.setText(consultas.get(position).getEspecialidade());
            data.setText(consultas.get(position).getData());
        }

        @Override
        public void onClick(View v) {
            ViewHolder viewHolder = (ViewHolder) recyclerView.findViewHolderForAdapterPosition(selectedItem);

            if (viewHolder != null) {
                viewHolder.imgExpand.setSelected(false);
                viewHolder.expandableLayout.collapse();
            }

            if (position == selectedItem) {
                selectedItem = UNSELECTED;
            } else {
                imgExpand.setSelected(true);
                expandableLayout.expand();
                selectedItem = position;
            }

        }
    }
}
```

And that's my layout file:

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txt_consulta_especialidade"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="6dp"
        android:foreground="?selectableItemBackground"
        android:padding="@dimen/activity_horizontal_margin"
        android:text="Especialidade 01" />

    <net.cachapa.expandablelayout.ExpandableLayout
        android:id="@+id/expandable_recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/img_expandable"
        app:el_duration="300"
        app:el_expanded="false">

        <TextView
            android:id="@+id/txt_consulta_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Data" />
    </net.cachapa.expandablelayout.ExpandableLayout>

</LinearLayout>
```

from expandablelayout.

cachapa avatar cachapa commented on July 21, 2024

Your layout file is incomplete.
Please post the exact code, otherwise it's almost impossible to figure out where the problem is.

from expandablelayout.

joaovictortinoco avatar joaovictortinoco commented on July 21, 2024

It was an edition error. Sorry about it. Updated!

from expandablelayout.

cachapa avatar cachapa commented on July 21, 2024

Sorry I couldn't replicate the issue.
Would it be possible to share a small project with the problem?

from expandablelayout.

joaovictortinoco avatar joaovictortinoco commented on July 21, 2024

Yep, i'll share with you soon.

from expandablelayout.

joaovictortinoco avatar joaovictortinoco commented on July 21, 2024

Check it out: https://github.com/joaovictortinoco/mobix-medflex-android/tree/medflex-v1

from expandablelayout.

cachapa avatar cachapa commented on July 21, 2024

I actually was looking for a small project that just shows the problem. I couldn't even find the screen where you use the recyclerview.

from expandablelayout.

joaovictortinoco avatar joaovictortinoco commented on July 21, 2024

Sorry man, the project is huge.

Look again, please.

You should look for the references in fragment folder, "MinhaConsultaFragment.java" that points to the layout. And if you run the application, the error log will be the first.

from expandablelayout.

cachapa avatar cachapa commented on July 21, 2024

Sorry but I don't have the time to dig through so much code.

The use case you mention works fine in the demo project, which you seem to have copied.
If you can't produce a compact example that shows the problem I'll have to assume the issue lies in your changes and close this report.

from expandablelayout.

joaovictortinoco avatar joaovictortinoco commented on July 21, 2024

Ok, then. Thanks anyway.

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.