我正试图从零碎的CreateView上填写图表和一些纽芬兰语。 我不知道如何把这两种观点结合起来。 我只能拿不上海图或布局:
public class ChartFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// LineGraph - class which draws the graph using achartengine
final LineGraph lineGraph = new LineGraph();
final GraphicalView chart = lineGraph.getGraphicalView(inflater.getContext());
final View view = inflater.inflate(R.layout.chart, container, false);
Button drawChartButton = (Button) view.findViewById(R.id.button_draw_chart);
drawChartButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// update chart for new data
}
});
return chart; //return the chart only
// return view; // return layout but without the chart
}
}
在活动中,以下法典:
Button chartButton = (Button) findViewById(R.id.button_draw_chart);
chartButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
LineGraph lineGrpah = new LineGraph();
GraphicalView testChart = lineGrpah
.getGraphicalView(SimpleApp.this);
layout.addView(testChart, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
});
页: 1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/chart"
android:layout_width="600dp"
android:layout_height="350dp"
android:layout_margin="15dp" >
</LinearLayout>
<Button
android:id="@+id/button_draw_chart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_draw_chart" />
</LinearLayout>
工作顺利进行,但我不知道如何分散这项工作。