如何使用achartengine为片段中的Intent充气(How to inflate an Intent in a fragment using achartengine)

编程入门 行业动态 更新时间:2024-10-10 03:22:48
如何使用achartengine为片段中的Intent充气(How to inflate an Intent in a fragment using achartengine)

下面的代码可以工作,但是当我调用自己时,整个主视图将替换为图表。

我想这个问题在于如何在startActivity(图表)中启动图表Activity; 在我的framgment中。 如果删除它,片段可以正常工作而无需替换。

我怎么能把它发送到主视图???

public class Graph extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ // LineGraph - class which draws the graph using achartengine final LineGraph lineGraph = new LineGraph(); final Intent chart = lineGraph.getIntent(inflater.getContext()); startActivity(chart); return inflater.inflate(R.layout.graph1, container, false); } }

这里的活动:

public class MainCharts extends Activity { Button btn1; @TargetApi(11) protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.dash_app); btn1=(Button)findViewById(R.id.button1); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); StartFragment myFragment = new StartFragment(); ft.add(R.id.myFragment, myFragment); ft.commit(); btn1.setOnClickListener(btnOnClickListener); } Button.OnClickListener btnOnClickListener = new Button.OnClickListener(){ @SuppressLint("NewApi") @Override public void onClick(View v){ Fragment newFragment; newFragment = new Graph(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.myFragment, newFragment); transaction.addToBackStack(null); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.commit(); } }; }

The code below works, but the whole main view is replaced for the chart when I invoke itself.

I guess that the problem is located in how I start the chart Activity in startActivity(chart); in my framgment. If remove it, the fragment works well without replacement.

How could I send it to the main view???

public class Graph extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ // LineGraph - class which draws the graph using achartengine final LineGraph lineGraph = new LineGraph(); final Intent chart = lineGraph.getIntent(inflater.getContext()); startActivity(chart); return inflater.inflate(R.layout.graph1, container, false); } }

Here the Activity:

public class MainCharts extends Activity { Button btn1; @TargetApi(11) protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.dash_app); btn1=(Button)findViewById(R.id.button1); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); StartFragment myFragment = new StartFragment(); ft.add(R.id.myFragment, myFragment); ft.commit(); btn1.setOnClickListener(btnOnClickListener); } Button.OnClickListener btnOnClickListener = new Button.OnClickListener(){ @SuppressLint("NewApi") @Override public void onClick(View v){ Fragment newFragment; newFragment = new Graph(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.myFragment, newFragment); transaction.addToBackStack(null); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.commit(); } }; }

最满意答案

看一下如何在片段中添加AChartEngine图表的示例。

Take a look at this for an example on how to add an AChartEngine chart inside a fragment.

更多推荐

本文发布于:2023-07-17 14:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1145649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   片段   achartengine   fragment   Intent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!