mikepenz / FastAdapter

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
https://mikepenz.dev
Apache License 2.0
3.84k stars 494 forks source link

Second added item is blank #1026

Closed ghutchins56 closed 2 years ago

ghutchins56 commented 2 years ago

About this issue

Details

Checklist

mikepenz commented 2 years ago

@ghutchins56 could you please share some code examples here. It's usually more open to collaborate more openly, so other people can also chime in and help.

ghutchins56 commented 2 years ago

I appreciate your prompt reply and suggestion. I made ghutchins56/GilCash public. I apologize for having made it private.

public class MainActivity extends AppCompatActivity { . . . @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); itemAdapter = new ItemAdapter<>(); FastAdapter fastAdapter = FastAdapter.with(itemAdapter); RecyclerView itemList = findViewById(R.id.item_list); itemList.setAdapter(fastAdapter); itemList.setLayoutManager(new LinearLayoutManager(this)); . . . } }

public class SimpleItem extends AbstractItem { private final String date;

public SimpleItem(String date) {
    this.date = date;
}

@Override
public int getType() {
    return R.id.simple_item;
}

@Override
public int getLayoutRes() {
    return R.layout.simple_item;
}

@NonNull
@Override
public ViewHolder getViewHolder(@NonNull View view) {
    return new ViewHolder(view);
}

protected static class ViewHolder extends FastAdapter.ViewHolder<SimpleItem> {
    TextView date;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        date = itemView.findViewById(R.id.date);
    }

    @Override
    public void bindView(@NonNull SimpleItem item, @NonNull List<?> list) {
        date.setText(item.date);
    }

    @Override
    public void unbindView(@NonNull SimpleItem item) {
        date.setText(null);
    }
}

}

mikepenz commented 2 years ago

I'll need to take a closer look at this. on the first look at the code I don't see anything immediately wrong.

Have you had the chance to build and try out the sample application? Which includes a lot of different ways to use the library.

mikepenz commented 2 years ago

One thing I see which may cause problems (unrelated to this library though).

Your RecyclerView is wrap_content so it may be wrongly sized: https://github.com/ghutchins56/GilCash/blob/master/app/src/main/res/layout/activity_main.xml#L12

You may wanna use match_parent instead. or align it fully in the layout

app:layout_constraintBottom_toTopOf="@id/add_item"

Don't forget to alignt he button also to the bottom:

    <ImageButton
        android:id="@+id/add_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:contentDescription="@string/add_item"
        android:minHeight="48dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/item_list"
        app:layout_constraintBottom_toBottomOf="@id/add_item"
        app:srcCompat="@drawable/icon_add" />
ghutchins56 commented 2 years ago

I appreciate the suggestions and will try them. I installed the sample app from the Play Store and used the simple item example without any problems. I'll try building the sample app project.

ghutchins56 commented 2 years ago

Your suggestion about the RecyclerView and wrap_content got me on the right track. I also changed the height of simple_item from match_parent to wrap_content. This last change fixed the rest of the problem. As you said, this was not a problem with the FastAdapter library.