![](/img/trans.png)
[英]How to update LinearLayout when clicking recycler view item in a bottom sheet fragment?
[英]How to update a view on LinearLayout for a fragment
我有一個片段GraphFragment,它在圖形上使用GraphView繪制我需要的所有數據。 我想為用戶提供更改GraphView的網格顏色的選項,但是當我嘗試更新視圖時,它似乎不起作用(沒有任何更改)。 setGridColor函數依賴於用戶按下的特定列表視圖索引。
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()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.