gpt4 book ai didi

java - 如果数据更改值,Android 饼图不会刷新饼图

转载 作者:行者123 更新时间:2023-12-01 16:52:39 26 4
gpt4 key购买 nike

我无法从监听器 Spinner 刷新饼图:Fragment 内的 setOnItemSelectedListener。

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

ArrayAdapter adapterSpinnerTeams = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, teamsName);
adapterSpinnerTeams.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerTeamsAnalysis.setAdapter(adapterSpinnerTeams);

spinnerTeamsAnalysis.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
anyChartView2 = v.findViewById(R.id.anyChartView2);
APIlib.getInstance().setActiveAnyChartView(anyChartView2);
setUpPieChart(spinnerTeamsAnalysis.getSelectedItem().toString());
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
return;
}

});

return v;
}

public void setUpPieChart(String teamSelected) {
anyChartView2 = v.findViewById(R.id.anyChartView2);
APIlib.getInstance().setActiveAnyChartView(anyChartView2);

Pie pie = AnyChart.pie();
List<DataEntry> dataEntries = new ArrayList<>();

creditsByRoles = calculateCredits(teamSelected, creditsByRoles);

for(int i=0; i<roles.length; i++) {
dataEntries.add(new ValueDataEntry(roles[i], creditsByRoles[i]));
}

pie.data(dataEntries);

pie.title("title");

anyChartView2.setChart(pie);
}

注意。方法calculateCredits(teamSelected, CreditsByRoles)返回一个Integer数组。

当微调器更改值时,饼图不会更改值。

有什么解决办法吗?

最佳答案

如果你想刷新图表,你必须使用这一行:

pie.invalidate();

调用invalidate()后,图表将刷新并绘制提供的数据。 docs.

关于java - 如果数据更改值,Android 饼图不会刷新饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61660760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com