我想使用this example中的一个类 示例显示一个列表,单击该按钮时,将打开另一个活动 我想要使用的函数代码
public class ChartDemo extends Activity {
private AverageCubicTemperatureChart TCh = new AverageCubicTemperatureChart();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = null;
intent = TCh.execute(this);
}
}
类 AverageCubicTemperatureChart
的代码/**
* Average temperature demo chart.
*/
public class AverageCubicTemperatureChart implements IDemoChart {
/**
* Returns the chart name.
*
* @return the chart name
*/
public String getName() {
return "Average temperature";
}
/**
* Returns the chart description.
*
* @return the chart description
*/
public String getDesc() {
return "The average temperature in 4 Greek islands (cubic line chart)";
}
/**
* Executes the chart demo.
*
* @param context the context
* @return the built intent
*/
public Intent execute(Context context) {
String[] titles = new String[] { "Crete", "Corfu", "Thassos", "Skiathos" };
List<double[]> x = new ArrayList<double[]>();
for (int i = 0; i < titles.length; i++) {
x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
}
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2,
13.9 });
values.add(new double[] { 10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14, 11 });
values.add(new double[] { 5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6 });
values.add(new double[] { 9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10 });
int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.CYAN, Color.YELLOW };
PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, PointStyle.DIAMOND,
PointStyle.TRIANGLE, PointStyle.SQUARE };
XYMultipleSeriesRenderer renderer = AbstractDemoChart.buildRenderer(colors, styles);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++) {
((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
}
AbstractDemoChart.setChartSettings(renderer, "Average temperature", "Month", "Temperature", 0, 100, 0, 100,
Color.LTGRAY, Color.LTGRAY);
renderer.setXLabels(12);
renderer.setYLabels(10);
renderer.setShowGrid(true);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(true);
renderer.setPanLimits(new double[] { 0, 200, 0, 100 });
renderer.setZoomLimits(new double[] { 0, 200, 0, 100 });
Intent intent = ChartFactory.getCubicLineChartIntent(context, AbstractDemoChart.buildDataset(titles, x, values),
renderer, 0.33f, "Average temperature");
return intent;
}
}
名为execute的函数返回一个intent,如何将当前视图设置为该intent而不是启动新活动
答案 0 :(得分:0)
在执行功能中,我恢复了上下文和父布局
在函数结束时和返回意图之前我添加了这一行
View mChartView2;
mChartView2=ChartFactory.getCubeLineChartView(context, AbstractDemoChart.buildDataset(titles, x, values), renderer, 0.33f);
parent.addView(mChartView2);