猿问
回到首页
个人中心
反馈问题
注册登录
下载APP
首页
课程
实战
体系课
手记
专栏
慕课教程
如何在单击按钮上启动新活动
如何在单击按钮上启动新活动
在Android应用程序中,当单击另一个活动中的按钮时,如何启动新活动(GUI),以及如何在这两个活动之间传递数据?
开心每一天1111
浏览 494
回答 3
3回答
海绵宝宝撒
创建ViewPerson活动的意图并传递PersonId(例如,用于数据库查找)。Intent i = new Intent(getBaseContext(), ViewPerson.class); i.putExtra("PersonID", personID);startActivity(i);然后,在ViewPerson活动中,您可以获得额外的数据包,确保它不是NULL(如果有时不传递数据的话),然后获取数据。Bundle extras = getIntent().getExtras();if(extras !=null){ personID = extras.getString("PersonID");}现在,如果需要在两个活动之间共享数据,也可以使用GlobalSingleton。public class YourApplication extends Application { public SomeDataClass data = new SomeDataClass();}然后在任何活动中调用它:YourApplication appState = ((YourApplication)this.getApplication());appState.data.CallSomeFunctionHere(); // Do whatever you need to with data here. Could be setter/getter or some other type of logic
0
0
0
打开App,查看更多内容
随时随地看视频
慕课网APP
相关分类
Android
继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续