• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Need help with RecyclerView

I'm working on a fairly simple calculator app as a way of learning Android development. I have the calculator mostly working mostly as intended, and am now working on creating a history feature. I want the history to be a separate activity where the user can see a list of all the calculations they've done during the current session. It would display a list of expressions such as:

5x6+8/4-7=25

The user should be able to select any of these expressions and have the final answer sent back to the main activity where they can use it for their next calculation. Currently, each calculation is stored as a linked list, with each node containing a number in the calculation in both string and double format, as well as the operator to be performed on the next number.

I'm struggling to figure out how to have my Java code create items in the UI that display each calculation. I've spent some time researching and it seems that I need a RecyclerView. I've been through the tutorials on how to use this, and while they make sense, none of them explain how to populate items in the RecyclerView with a string from my Java code. The purpose of this project is to learn, so I want to avoid importing some library. I want to understand how this works. If anyone can offer any suggestions I'd really appreciate it.
 
none of them explain how to populate items in the RecyclerView with a string from my Java code

All the work of managing items in the RecyclerView is done by the Adapter class. You would normally declare a List variable within the Adapter class to contain all your list items. This variable is initialised by passing in a constructor parameter:

Code:
public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.MyViewHolder> {

    private List<Movie> moviesList;
    ...

    public MoviesAdapter(List<Movie> moviesList) {
        this.moviesList = moviesList;
    }
    ...
}


This is a pretty good tutorial

https://www.androidhive.info/2016/01/android-working-with-recycler-view/
 
All the work of managing items in the RecyclerView is done by the Adapter class. You would normally declare a List variable within the Adapter class to contain all your list items. This variable is initialised by passing in a constructor parameter:

Code:
public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.MyViewHolder> {

    private List<Movie> moviesList;
    ...

    public MoviesAdapter(List<Movie> moviesList) {
        this.moviesList = moviesList;
    }
    ...
}


This is a pretty good tutorial

https://www.androidhive.info/2016/01/android-working-with-recycler-view/
This is exactly what I needed, thank you!
 
Back
Top Bottom