I have a fragment , GraphFragment which plots all the data I need using GraphView on a graph. I want to give the user the option to change the gridcolor of the GraphView but when I try to update the view it doesn't seem to work (nothing changes). The setGridColor function relised on the specific listview index the user presses.
public class GraphFragment extends Fragment {
private GraphView graphView;
LinearLayout layout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.graph_fragment, container, false);
//Initialise the glucose level graph
graphView = new LineGraphView(this.getActivity(), "Blood Glucose (mmol/l)");
graphView.getGraphViewStyle().setVerticalLabelsWidth(40);
//Add the test data
graphView.addSeries(testSeries);
layout = (LinearLayout) rootView.findViewById(R.id.graph1);
layout.addView(graphView);
}
public void setGridColor (int position){
if(position==0){
//graphView = new LineGraphView(this.getActivity(), "Blood Glucose (mmol/l)");
layout.removeView(graphView);
graphView.getGraphViewStyle().setGridColor(Color.RED);
layout.addView(graphView);
}
if(position==1){
//graphView = new LineGraphView(this.getActivity(), "Blood Glucose (mmol/l)");
layout.removeView(graphView);
graphView.getGraphViewStyle().setGridColor(Color.BLUE);
layout.addView(graphView);
}
if(position==2){
//graphView = new LineGraphView(this.getActivity(), "Blood Glucose (mmol/l)");
layout.removeView(graphView);
graphView.getGraphViewStyle().setGridColor(Color.GREEN);
layout.addView(graphView);
}
}
}
更改后,尝试运行graphView.invalidate()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.