Ramotion/folding-cell-android

Cannot able to genrate List With RecyclerView

Addynt opened this issue · 5 comments

MyAdapter.java Code

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

List<CoursesFoldingCellModelClass> coursesFoldingCellModelClasses;
Context context;

public MyAdapter(List<CoursesFoldingCellModelClass> coursesFoldingCellModelClasses, Context context) {
    this.coursesFoldingCellModelClasses = coursesFoldingCellModelClasses;
    this.context = context;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
    View v = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.foldingcelllayout,parent,false);
    return new ViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {

    CoursesFoldingCellModelClass coursesFoldingCellModelClass = coursesFoldingCellModelClasses.get(i);

    viewHolder.coursename.setText(coursesFoldingCellModelClass.getCoursename());
    viewHolder.eligibility.setText(coursesFoldingCellModelClass.getEligibility());
    viewHolder.courseimage.setImageResource(coursesFoldingCellModelClass.getCourseimage());
    viewHolder.coursedescription.setText(coursesFoldingCellModelClass.getCoursedescription());
    viewHolder.admissionprocedure.setText(coursesFoldingCellModelClass.getAdmissionprocedure());
}

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

public class ViewHolder extends RecyclerView.ViewHolder{

    public TextView coursename;
    public TextView eligibility;
    public ImageView courseimage;
    public TextView coursedescription;
    public TextView admissionprocedure;
    CardView cv;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        coursename =(TextView)itemView.findViewById(R.id.course_name);
        eligibility =(TextView)itemView.findViewById(R.id.eligibility);
        courseimage =(ImageView) itemView.findViewById(R.id.course_image);
        coursedescription =(TextView)itemView.findViewById(R.id.course_description);
        admissionprocedure =(TextView)itemView.findViewById(R.id.admission_procedure);

        cv = (CardView) itemView.findViewById(R.id.card_view);

        final FoldingCell fc = (FoldingCell)itemView.findViewById(R.id.folding_cell);
        fc.initialize(1000, Color.DKGRAY, 2);
        fc.setTag(cv);


        fc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fc.toggle(false);
            }
        });
    }
}

}
/ModelClass/
CoursesFoldingCellModelClass.java

package com.example.addyn.foldingcellwithrecyclerview;

public class CoursesFoldingCellModelClass {

private String coursename;
private String eligibility;
private int courseimage;
private String coursedescription;
private String admissionprocedure;

public CoursesFoldingCellModelClass(String coursename, String eligibility, int courseimage, String coursedescription, String admissionprocedure) {
    this.coursename = coursename;
    this.eligibility = eligibility;
    this.courseimage = courseimage;
    this.coursedescription = coursedescription;
    this.admissionprocedure = admissionprocedure;
}

public String getCoursename() {
    return coursename;
}

public void setCoursename(String coursename) {
    this.coursename = coursename;
}

public String getEligibility() {
    return eligibility;
}

public void setEligibility(String eligibility) {
    this.eligibility = eligibility;
}

public int getCourseimage() {
    return courseimage;
}

public void setCourseimage(int courseimage) {
    this.courseimage = courseimage;
}

public String getCoursedescription() {
    return coursedescription;
}

public void setCoursedescription(String coursedescription) {
    this.coursedescription = coursedescription;
}

public String getAdmissionprocedure() {
    return admissionprocedure;
}

public void setAdmissionprocedure(String admissionprocedure) {
    this.admissionprocedure = admissionprocedure;
}

}

MainActivity.java

package com.example.addyn.foldingcellwithrecyclerview;

import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import com.ramotion.foldingcell.FoldingCell;
import java.util.ArrayList;
import java.util.List;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class MainActivity extends AppCompatActivity {

private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;

private List<CoursesFoldingCellModelClass> coursesFoldingCellModelClasses;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recyclerView = (RecyclerView)findViewById(R.id.recyclerViewForCourses);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    coursesFoldingCellModelClasses = new ArrayList<>();
    coursesFoldingCellModelClasses.add(new CoursesFoldingCellModelClass("Computer Science Engineering With AI","(10+2)PCM",R.drawable.cat1,"My Name is Addy Prakash Nautiyal","U Can Apply Online as Well as Offline"));
    coursesFoldingCellModelClasses.add(new CoursesFoldingCellModelClass("Computer Science Engineering With AI","(10+2)PCM",R.drawable.cat1,"My Name is Addy Prakash Nautiyal","U Can Apply Online as Well as Offline"));
    coursesFoldingCellModelClasses.add(new CoursesFoldingCellModelClass("Computer Science Engineering With AI","(10+2)PCM",R.drawable.cat1,"My Name is Addy Prakash Nautiyal","U Can Apply Online as Well as Offline"));

    adapter =new MyAdapter(coursesFoldingCellModelClasses,this);
    recyclerView.setAdapter(adapter);

    // get our folding cell
}

}

activity_main.xml

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerViewForCourses"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>

foldingcell.xml

<androidx.cardview.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<com.ramotion.foldingcell.FoldingCell
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/folding_cell"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    folding-cell:animationDuration="1000"
    folding-cell:backSideColor="#373737"
    folding-cell:additionalFlipsCount="1"
    folding-cell:cameraHeight="30">
    ​
    <FrameLayout
        android:id="@+id/cell_content_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#E5E5E5">

            <TextView
                android:id="@+id/course_name_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="Computer Science with Cloud Computing"
                android:textAlignment="center"
                android:textColor="@android:color/white"
                android:textSize="18sp"
                android:textStyle="bold"
                android:background="@drawable/border_layout"/>

            <ImageView
                android:id="@+id/course_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/cat1"
                android:layout_margin="10dp"
                android:scaleType="fitXY"
                android:elevation="4dp"/>


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp">


                <TextView
                    android:id="@+id/course_description"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Hello My name is Bhanu Prakash Nautiyal And i am pursuing my Graducation from Graphic Era Hill University and currently i am in my 8th Semester"
                    android:textColor="#000"
                    android:textSize="15sp"
                    android:layout_marginTop="8dp"/>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center">
                    <ImageView
                        android:id="@+id/logo"
                        android:layout_width="130dp"
                        android:layout_height="130dp"
                        android:scaleType="fitCenter"
                        android:alpha="0.2"
                        android:src="@drawable/logo_geu_deemed_flame" />

                </RelativeLayout>
                <LinearLayout
                    android:id="@+id/admission_procedure_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"
                    android:layout_below="@+id/course_description">

                    <TextView
                        android:layout_width="300dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textStyle="bold"
                        android:textColor="#000"
                        android:text="Admission Procedure:"/>

                    <TextView
                        android:id="@+id/admission_procedure"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textColor="#000"
                        android:layout_weight="1"
                        android:text="Merit prepared on basis of (10+2)% / JEE Main Score"/>

                </LinearLayout>

                <Button
                    android:id="@+id/Apply_Now_Btn"
                    android:layout_below="@+id/admission_procedure_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_red_dark"
                    android:text="Apply Now"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:textColor="@android:color/white" />

            </RelativeLayout>




        </LinearLayout>

    </FrameLayout>
    ​
    <FrameLayout
        android:id="@+id/cell_title_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:background="#E5E5E5"
            android:baselineAligned="false"
            android:orientation="vertical">

            <!-- LEFT TITLE PART -->



            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="150dp"
                    android:layout_height="match_parent"
                    android:background="#343434"
                    android:gravity="center"
                    android:orientation="vertical">


                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Eligibility"
                        android:textAlignment="center"
                        android:textColor="@android:color/white"
                        android:textSize="18sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/eligibility"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="(10+2) PCM"
                        android:layout_marginTop="4dp"
                        android:textAlignment="center"
                        android:textColor="#fff"
                        android:textSize="18sp" />

                </LinearLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


                    <TextView
                        android:id="@+id/course_name"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="8dp"
                        android:text="Computer Science with Cloud Computing"
                        android:textAlignment="center"
                        android:textColor="@android:color/black"
                        android:textSize="20sp"
                        android:textStyle="bold"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/course_name"
                        android:layout_marginTop="1dp"
                        android:textAlignment="center"
                        android:padding="8dp"
                        android:text="Show Details"
                        android:textSize="20sp"
                        android:textColor="@android:color/black"/>
                </RelativeLayout>

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@android:color/holo_red_dark"
                    android:textColor="@android:color/white"
                    android:text="Course Fee"
                    android:elevation="2dp"/>

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@android:color/holo_red_dark"
                    android:textColor="@android:color/white"
                    android:text="Curriculum"
                    android:elevation="2dp"/>

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@android:color/holo_red_dark"
                    android:textColor="@android:color/white"
                    android:text="Apply Now"
                    android:elevation="2dp"/>

            </LinearLayout>
        </LinearLayout>
    </FrameLayout>
    ​
</com.ramotion.foldingcell.FoldingCell>
</androidx.cardview.widget.CardView>

If anyone can help, this is my full project

Hello, @Addynt. Please be more specific with your question.

Thank you the response @golovin47 ,
I am trying to use recyclerView instead of ListView. And i am not able to do so.
in my code folding cell works fine, but ionly one cell in output instead of 3 cell in list form. Can u help me with the solution what i have done wrong in my code.
i have posted the code of MyAdapted.java, MainActivity.java, and model Class above.

If i understand you correctly, your recyclerview shows only one item in the list instead of three. I don't think it is related to folding cell library. To be sure that this issue has nothing to do with folding cell, you may replace folding cell to any other viewgroup in your layout. After that, if this issue still reproduce, you should find a bug in your implementation. If you won't be successful with it, you may use a listview as in example.

i have a problem with folding cell if i used list view in content layout i cant toggle the item
this code stopping work
((FoldingCell) view).toggle(false);
adapter.registerToggle(pos);