在具有 Intent 的 Android Activity 页面上添加后退按钮
我是 Android 开发新手。我想绘制折线图并使用 achartengine 来绘制图表。我成功绘制了图表。
现在面临的问题是我有一个应用程序,其中要添加该图表并在图表顶部添加“返回”按钮。
我的代码如下下面
public class Demo extends Activity {
Intent intent = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intent = new MyChart().execute(getApplicationContext());
startActivity(intent);
}
}
是执行图表的代码
public class MyChart extends AbstractDemoChart {
public Intent execute(Context context) {
...
...
...
...
...
return ChartFactory.getTimeChartIntent(context,buildDateDataset(titles, tempDatesList, weightList), renderer, format);
}
}
现在我想在 /layout/main.xml 中添加一个 xml 文件,其中将绘制图表,并在顶部某处添加一个后退按钮,整个图表如下它..请帮助我
I am a newbie to Android development. I want to plot a Line Chart and have used achartengine to draw the Chart. I got success in drawing the graph.
The issue now am facing is I have an application where this chart is to be added with a "BACK" button on the top of the chart.
My Code is as under
public class Demo extends Activity {
Intent intent = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intent = new MyChart().execute(getApplicationContext());
startActivity(intent);
}
}
Below is the code which executes the Graph
public class MyChart extends AbstractDemoChart {
public Intent execute(Context context) {
...
...
...
...
...
return ChartFactory.getTimeChartIntent(context,buildDateDataset(titles, tempDatesList, weightList), renderer, format);
}
}
Now I want to add an xml file in /layout/main.xml where in the chart would be drawn and with a back button added somewhere on the top with the entire chart below it.. Please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用线性或相对布局。在该位置有一个名为“返回”的按钮,其下方放置了图表的 xml 布局。并且还在您的活动类(演示类)中使用 setContentView(R.layout.main) 。
You can use a linear or relative layout. In that place a button named "Back" and below it place the xml layout for the chart. And also use setContentView(R.layout.main) in your activity class(Demo Class).
您可以添加一个按钮,只需在单击按钮时调用
finish();
即可完成 Activity。当您完成该活动时,它将加载之前正在执行的活动。You can add a button, and just call
finish();
to finish the Activity when the button is clicked. When you are finishing the activity, it will load the previous activity which was executing.