I'm not exactly sure if my topic is asking the right question but the situtation is this. I working on an app that is performing multiple calculations in separate classes. The calculations are being done correctly and I am able to see that they are in logcat. Now I want to display them in recyclerview and to do that I am trying to add them to an arraylist before doing a recyclerview. My arraylist is getting the values displayed in the title and its not showing in my recyclerview. Here is are my codes but based on the research I looked up I cant see what I am doing wrong.
ArrayList Code:
public class PlanetData {
private String planetRA;
private PlanetData(String planetRA){
this.planetRA = planetRA;
}
public String getPlanetRA(){
return planetRA;
}
public void setPlanetRA (String planetRA){
this.planetRA = planetRA;
}
public static void main(String [] args){
List<PlanetData> planetvalues = new ArrayList<>();
planetvalues.add(new PlanetData("12"));
planetvalues.add(new PlanetData(Double.toString(Mercury.getMercuryRA())));
planetvalues.add(new PlanetData(Double.toString(Venus.getVenusRA())));
planetvalues.add(new PlanetData(Double.toString(Moon.getMoonRA())));
planetvalues.add(new PlanetData (Double.toString(Mars.getMarsRA())));
planetvalues.add(new PlanetData(Double.toString(Jupiter.getJupiterRA())));
planetvalues.add(new PlanetData(Double.toString(Saturn.getSaturnRA())));
planetvalues.add(new PlanetData(Double.toString(Uranus.getUranusRA())));
planetvalues.add(new PlanetData(Double.toString(Neptune.getNeptuneRA())));
planetvalues.add(new PlanetData(Double.toString(Pluto.getPlutoRA())));
System.out.println("This is the arraylist" + planetvalues);
}
}
RecyclerView Adapter
public class PlanetRecyclerViewAdapter extends RecyclerView.Adapter<PlanetRecyclerViewAdapter.ViewHolder> {
List<PlanetData> mPlanetDataList;
Context mContext;
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView currentRA;
public ViewHolder(View itemView) {
super(itemView);
currentRA = (TextView) itemView.findViewById(R.id.planet_location);
}
}
public PlanetRecyclerViewAdapter(List<PlanetData> mPlanetDataList, Context mContext){
this.mPlanetDataList = mPlanetDataList;
this.mContext = mContext;
}
@Override
public PlanetRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.planet_recycler_item,parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder( PlanetRecyclerViewAdapter.ViewHolder holder, int position) {
holder.currentRA.setText(mPlanetDataList.get(position).getPlanetRA());
}
@Override
public int getItemCount() {
return mPlanetDataList.size();
}
}
Fragment Activity
public class TestFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private TextView planetLongitude;
private TextView planetLatitude;
private TextView planetTime;
private TextView SunRA;
private TextView SunDEC;
RecyclerView mRecyclerView;
PlanetRecyclerViewAdapter adapter;
List<PlanetData> items = new ArrayList<>();
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
Mercury test;
private OnFragmentInteractionListener mListener;
public TestFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment TestFragment.
*/
// TODO: Rename and change types and number of parameters
public static TestFragment newInstance(String param1, String param2) {
TestFragment fragment = new TestFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_test, container, false);
mRecyclerView = (RecyclerView)view.findViewById(R.id.planet_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new DividerItemDecoration(mRecyclerView.getContext(),DividerItemDecoration.VERTICAL));
adapter = new PlanetRecyclerViewAdapter(items, mRecyclerView.getContext());
mRecyclerView.setAdapter(adapter);
return view;
}
In my logcat I'm getting the following response in my arraylist: 11-10 22:02:52.581 13826-13826/com.ksburneytwo.planetmathtest I/System.out: This is the arraylist[com.ksburneytwo.planetmathtest.PlanetData@adf4bee, com.ksburneytwo.planetmathtest.PlanetData@24a088f, com.ksburneytwo.planetmathtest.PlanetData@5bb671c, com.ksburneytwo.planetmathtest.PlanetData@5dd9f25, com.ksburneytwo.planetmathtest.PlanetData@17838fa, com.ksburneytwo.planetmathtest.PlanetData@ce89eab, com.ksburneytwo.planetmathtest.PlanetData@2a5d908, com.ksburneytwo.planetmathtest.PlanetData@cee08a1, com.ksburneytwo.planetmathtest.PlanetData@580eac6, com.ksburneytwo.planetmathtest.PlanetData@a907a87]
The values should be my the results of my calculations.