【问题标题】:How to inflate an Intent in a fragment using achartengine如何使用 achartengine 在片段中膨胀 Intent
【发布时间】:2012-10-10 11:40:56
【问题描述】:

下面的代码有效,但是当我调用它自己时,整个主视图被替换为图表。

我猜问题出在我如何在startActivity(chart)中启动图表Activity;在我的片段中。如果删除它,该片段无需替换即可正常工作。

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

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();
        }
    };
}

【问题讨论】:

    标签: android android-intent android-fragments achartengine


    【解决方案1】:

    查看this 以获取有关如何在片段中添加 AChartEngine 图表的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多