我不確定我的主題是否提出了正確的問題,但情況就是這樣。我正在開發一個在單獨的類中執行多個計算的應用程序。計算正確完成,我可以看到它們在 logcat 中?,F在我想在 recyclerview 中顯示它們,為此我試圖在執行 recyclerview 之前將它們添加到數組列表中。我的數組列表正在獲取標題中顯示的值,而它沒有顯示在我的回收站視圖中。這是我的代碼,但根據我查找的研究,我看不出我做錯了什么。數組列表代碼: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 適配器 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); } }
1 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
默認情況下,toString()
方法將導致packagename.ClassName@hashcode
.
在您的PlanetData
類中,您需要重寫toString()
方法,以便它可以返回適當的字段及其值。
您可以toString()
使用 IDE生成方法并選擇要包含在輸出中的字段。
添加回答
舉報
0/150
提交
取消