意图(Intent)讲解4:安卓使用意图(Intent)静态变量方法传递数据
来源:互联网 发布:淘宝买家具很久不发货 编辑:程序博客网 时间:2024/06/05 07:25
安卓使用意图(Intent)静态变量方法传递数据,将该方法的使用分享给大家。
整体思路:在OtherActivity中定义两个静态变量name、age,在MainActivity中对这两个静态变量进行赋值,跳转到OtherActivity,在OtherActivity中显示两个静态变量。
activity_main.xml文件:
<span style="color:#cc33cc;"> </span><Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用静态变量传递数据" />activity_other.xml文件:
<TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" />
MainActivity.java文件:
private Button button;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button=(Button)findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {public void onClick(View arg0) {// TODO Auto-generated method stubIntent intent=new Intent(MainActivity.this,OtherActivity.class);OtherActivity.age=23;OtherActivity.name="zhaochong";startActivity(intent);}});}
OtherActivity.java文件:
private TextView textView;public static String name;//定义静态变量public static int age; protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_other); textView=(TextView)findViewById(R.id.textview); textView.setText(name+age); }注意:不要忘记注册新创建的activity。
1 0
- 意图(Intent)讲解4:安卓使用意图(Intent)静态变量方法传递数据
- 意图(Intent)讲解1:安卓使用意图(Intent)通用方法传递数据
- 意图(Intent)讲解3:安卓使用意图(Intent)全局变量方法传递数据
- 意图(Intent)讲解5:安卓使用意图(Intent)剪切板方法传递数据
- 意图(Intent)讲解2:安卓使用意图(Intent)传递数据并返回结果
- Intent使用意图(三)
- Intent使用意图(二)
- Intent(意图)
- Intent(意图)
- Intent(意图)
- Android-Intent(意图)
- 安卓 Intent意图详解
- Intent使用意图(一)添加Category
- andorid使用intent意图来传递全局变量
- 显示Intent和隐式Intent的使用(意图)
- Intent意图的使用
- intent意图过滤器(intent-filter)
- Android --Intent意图的讲解
- 自定义函数
- qt delegate drawDisplay()
- C++继承与派生的概念
- Linux-CentOS安装jdk以及配置
- *LeetCode-Multiply Strings
- 意图(Intent)讲解4:安卓使用意图(Intent)静态变量方法传递数据
- Spark执行样例报警告:WARN scheduler.TaskSchedulerImpl: Initial job has not accepted any resources
- Xcode7 &&iOS9一些新特性 记录
- 八卦CSDN博客排名
- SEERC 2006 Subsequence, 高效算法设计 ,LA 2678
- 树莓派raspberry pi安装archlinux,并且在上面搭建以太坊(ethereum)环境
- 最小生成树(poj1251 poj1861 poj1789)
- c语言的二级别指针
- INotifyPropertyChanged 接口