简体   繁体   English

如何将这个Custom ListView ArrayAdapter连接在一起?

[英]How can I wire together this Custom ListView ArrayAdapter?

This question isn't specific to the MPAndroidChart lib, but I'm expanding on the MPAndroidChart example app's ListViewMultiChartActivity ChartDataAdapter , and it abstracts out the RowItems ( ChartItem s in this case). 这个问题并非特定于MPAndroidChart库,而是在MPAndroidChart示例应用程序的ListViewMultiChartActivity ChartDataAdapter ,它抽象出RowItems(在这种情况下为ChartItem )。 Now, I'm used to holding all of my logic in the ArrayAdapter's getView() , but in this case, it seems to be abstracted out into their own classes . 现在,我习惯于将所有逻辑保存在ArrayAdapter的getView() ,但是在这种情况下,它似乎被抽象到了自己的类中 My problem is being able to update the ChartItem from within the different ChartItem s.. 我的问题是能够更新ChartItem从内不同ChartItem秒。

Should I be passing through a copy of the ArrayAdapter , or the ArrayList<ChartItem> , into my different ChartItem getViews() ? 我应该将ArrayAdapter的副本还是ArrayList<ChartItem> getViews()到我的不同ChartItem getViews() I have no issue holding and passing the reference/position in my chart's tag, but I still don't know how to update that single row in the list and update the adapter FROM the ChartItem itself. 我在保持和传递图表标记中的引用/位置方面没有问题,但是我仍然不知道如何更新列表中的该行以及如何从ChartItem本身更新适配器。

I've tried different methods.. I've tried abstracting out getItem() into each ChartItem , but I don't think I understand Java abstraction enough to get what's going on here. 我尝试了不同的方法。我尝试将getItem()抽象到每个ChartItem ,但是我认为我对Java抽象的理解不足以了解发生了什么。 I've tried referencing the ChartItem as this in each ChartItem , and while I can update the row, it updates every other row of the same ChartItem type.. 我试着引用ChartItem因为this在每个ChartItem ,而我可以更新该行,它更新相同的每隔一行ChartItem类型..

I'm sure it's something simple I'm not wrapping my head around.. I think it has to do with the abstraction and not fully understanding what's happening there. 我敢肯定,这很简单,我没弄清楚。.我认为这与抽象有关,并且没有完全了解那里发生的事情。 I'd rather not move all of my ChartItem getView logic into my ArrayAdapter. 我不想将我所有的ChartItem getView逻辑都移到ArrayAdapter中。 I can't seem to find one other example where the RowItems/ChartItems are abstracted out like this.. at least not with updates to the list. 我似乎找不到其他示例,其中RowItems / ChartItems像这样抽象出来..至少没有更新列表。 Thanks. 谢谢。

EDIT 编辑

I've been messing with the ChartData<cd> that's being passed into my LineChartItem , and I can successfully modify datasets and have the change persists against re-draws of the list.. and then I'm calling chart.invalidate() and cd.notifyDataSetChanged() .. but my changes don't persist on rotation.. 我一直在混乱传递给LineChartItemChartData<cd> ,并且我可以成功地修改数据集,并使更改在列表的重新绘制后仍然存在..然后我调用chart.invalidate()cd.notifyDataSetChanged() ..但我的更改不会持续旋转。

I finally figured out how to save the ChartItem s ChartData<?> for anyone else in the same boat.. I made my ChartItem implement Parcleable and then flattened the ChartData array into a Json string based on this answer . 我终于想出了如何在同一条船上为其他人保存ChartItemChartData<?>的方法。我使ChartItem实现Parcleable ,然后根据此答案将ChartData数组展平为Json字符串。 Works like a charm.. 奇迹般有效..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM