我正在构建一个经典的菜单/细节片段平板电脑活动。
我的详细信息片段是由外部库生成的 Graph。这个库给了我一个意图或我的图表的视图。
当我点击我的菜单时,我想刷新我的图表。
这是我的活动代码:
public class myActivity extends FragmentActivity {
Context context;
Graphical graphical;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
setContentView(R.layout.fragment_suivi_conso_graph);
}
/**
* Called when clicking on the menu Fragment
*/
public void onChooseGraph(UrlAction urlAction){
GraphFragment graphFragment = (GraphFragment) getSupportFragmentManager().findFragmentById(R.id.graph_fragment);
if (graphFragment == null || !graphFragment.isInLayout()) {
Intent intentGraph;
intentGraph = graphical.executeForIntent(this, urlAction);
startActivity(intentGraph);
}
else {
View graphView = graphFragment.loadGraph(urlAction);
// I don't know what to do with this View !
}
}
这是我的详细片段代码:
public class GraphFragment extends Fragment {
private Context context;
private Graphical graphical;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this.getActivity();
graphical = new Graphical();
View graphView = null;
graphView = graphical.executeForView(context, UrlAction.CONSO_WEEKS);
return graphView;
}
public View loadGraph(UrlAction urlAction) {
Log.d("GraphFragment","[loadGraph] START");
View graphView = graphical.executeForView(context, urlAction);
//This graphView contains the graph I want to display in my graphFragment
return graphView;
}
}
我不知道我是否可以将片段视图重新加载到片段的loadGraph函数中。或者我是否需要在onChooseGraph函数中进行活动。
在这两种情况下,我都不知道如何刷新。