Android静态传参数(五)
来源:互联网 发布:rds mysql 慢 编辑:程序博客网 时间:2024/06/14 14:20
一、新建OtherActivity.java
public class OtherActivity extends Activity {<span style="color:#ff0000;">public static String name;public static int age;</span>private TextView textview;protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.other); textview = (TextView)this.findViewById(R.id.msg); textview.setText("name:"+name+",age:"+age); }}
定义静态变量name,age.
二、在MainActivity.java,跳转页面的时候调用class OtherActivity的静态变量name、age参数传入
public class MainActivity extends Activity {Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)this.findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent();intent.setClass(MainActivity.this,OtherActivity.class);<span style="color:#ff0000;">OtherActivity.age = 23;OtherActivity.name ="deng";</span>startActivity(intent);}}); }}
1)activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="match_parent" android:text="静态变量传参数测试" /></RelativeLayout>
<?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:orientation="vertical" > <TextView android:id="@+id/msg" android:layout_width="match_parent" android:layout_height="wrap_content"> </TextView></LinearLayout>
</pre><pre code_snippet_id="620199" snippet_file_name="blog_20150315_6_982152" name="code" class="html">3)AndroidManifest.xml
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.intent_static" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.intent_static.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OtherActivity" /> </application></manifest>
0 0
- Android静态传参数(五)
- Android Stuido Ndk-Jni 开发(五):Jni回调java静态方法和非静态方法
- 静态html传参数
- 静态页htm传参数
- html静态页面传参数
- 静态页htm传参数
- 静态页htm传参数 .
- appium (五)desired_caps参数
- PHP伪静态简单实现(五)
- (五)3 IO静态映射
- Android-调用本地方法传递数组参数/NDK-JNI开发实例(五)
- javascript html 静态页面传参数
- 读静态页面传的参数
- Android JNI编程(五)——C语言的静态内存分配、动态内存分配、动态创建数组
- Android手机壁纸(静态)
- Java基础(五)---局部变量、全局变量、静态变量、final变量、静态常量、静态方法
- java基础篇(五)——静态变量、静态方法、静态类
- SpringMVC学习笔记(五):参数传递
- 初识struts2和hibernate在MyEclipse下整合
- MySQL监控工具之orzdba
- 详解System.Data 命名空间
- 基于Mysql Connector(C++)的数据库连接池的实现
- nginx的4个学习资料
- Android静态传参数(五)
- C# FTP操作类
- percona之pt-table-checksum介绍
- 逃出你的肖申克(一):为什么一定要亲身经历了之后才能明白?笔记
- android AVD(模拟器)create里找不到snapshot
- Objective-C基础学习笔记(二)-面向对象与面向过程的两种思想
- MySQL监控工具之mytop
- Apache OFBIZ快速上手(三)--目录&&配置文件介绍
- 求两个值的最大公约数