Eiji
Eiji

Reputation: 453

recyclerview not displaying all data

I'm trying to adapt a recyclerview to display a list of objects. But actually I have some kind of wierd bug. My object have ID and Name data to display, but in the list, at first, I only can see the Id, and when I scroll down, only the rows going completely out of the screen are completely displayed...

This is my ListPresentActivity.

public class ListPresentActivity extends AppCompatActivity implements ViewInterface {

private static final String EXTRA_PRESENT_ID = "EXTRA_PRESENT_ID";
private static final String EXTRA_PRESENT_NAME = "EXTRA_PRESENT_NAME";

private List<PresentItem> listOfPresent;

private LayoutInflater layoutInflater;
private RecyclerView recyclerView;
private CustomAdapter adapter;

private PresentController presentController;


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


    recyclerView = (RecyclerView) findViewById(R.id.rec_list_activity);
    recyclerView.setHasFixedSize(true);

    layoutInflater = getLayoutInflater();

    presentController = new PresentController(this, new FakePresentModel());
}

@Override
public void startDetailActivity(int id, String name, String info, String target, String advice, String price) {
//public void startDetailActivity(int id) {
    Intent i = new Intent(this,PresentDetailActivity.class);
    i.putExtra(EXTRA_PRESENT_ID, id);
    i.putExtra(EXTRA_PRESENT_NAME, name);

    startActivity(i);
}

@Override
public void setUpAdapterAndView(List<PresentItem> listOfPresent) {
    this.listOfPresent = listOfPresent;

    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    adapter = new CustomAdapter();
    recyclerView.setAdapter(adapter);
}

private class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomViewHolder>{


    @Override
    public CustomAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = layoutInflater.inflate(R.layout.item_present, parent, false);

        return new CustomViewHolder(v);
    }

    @Override
    public void onBindViewHolder(CustomAdapter.CustomViewHolder holder, int position) {

        PresentItem currentPresent = listOfPresent.get(position);

        holder.id.setText(
                Integer.toString(currentPresent.getId())
        );

        holder.name.setText(
                currentPresent.getName()
        );
    }

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

    class CustomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        private TextView id;
        private TextView name;
        private ViewGroup container;

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

            this.id = (TextView) itemView.findViewById(R.id.texv_item_id);
            this.name = (TextView) itemView.findViewById(R.id.texv_item_name);

            this.container = (ViewGroup) itemView.findViewById(R.id.root_list_present);

            this.container.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
            PresentItem presentItem = listOfPresent.get(
                    this.getAdapterPosition()
            );

            presentController.onListItemClick(presentItem);
        }
    }

}
}

The layout item_present.xml

<android.support.constraint.ConstraintLayout 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="88dp"
android:id="@+id/root_list_present"
xmlns:tools="http://schemas.android.com/tools">

<TextView
    android:id="@+id/texv_item_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:textSize="48sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:text="#id" />

<TextView
    android:id="@+id/texv_item_name"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="84dp"
    android:layout_marginTop="8dp"
    android:ellipsize="end"
    android:maxLines="1"
    android:textSize="20sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:text="collier" />

</android.support.constraint.ConstraintLayout>

And my list layout

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.lubbee.bruh.view.ListPresentActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/rec_list_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.constraint.ConstraintLayout>

I have search for a long time now, and the only concording result I have fount seems to be fixed with the recyclerView.setHasFixedSize(true); which is not my case...

Thanks for your time!

PS : If there is some code parts needed missing, just say the word! :]

enter image description here

enter image description here

Just after the first loading.

After one scroll to the bottom and back to the top of the screen enter image description here

Upvotes: 0

Views: 843

Answers (1)

Ionut J. Bejan
Ionut J. Bejan

Reputation: 754

<LinearLayout android:layout_width="match_parent"
    android:layout_height="88dp"
    android:weightSum="1"
    xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
    android:layout_gravity="center_vertical"
    android:layout_weight="0.2"
    android:layout_width="0dp"
    android:layout_height="wrap_content" />

<TextView
    android:layout_gravity="center_vertical"
    android:layout_weight="0.8"
    android:layout_width="0dp"
    android:layout_height="wrap_content" />

</LinearLayout>

Try this simple LinearLayout it should work You can also add other properties, but for now try it out

Upvotes: 1

Related Questions