Android 页面间传值(多个数据)
来源:互联网 发布:淘宝客户申请假冒品牌 编辑:程序博客网 时间:2024/06/05 20:51
1.Android 页面间传值(多个数据)先将数据封装到Bundle类中,以键--值对保存。在主Activity的OnClick事件中封装Bundle。然后将Bundle对象放到Intent中。
package com.fruit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class IntantTextActivity extends Activity implements OnClickListener {
private EditText username, password;
private Button b1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
b1 = (Button) findViewById(R.id.Button01);
b1.setOnClickListener(this);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.Button01:
String str_username = username.getText().toString();
String str_password = password.getText().toString();
Bundle b = new Bundle();
b.putString("username", str_username);
b.putString("password", str_password);
Intent intent = new Intent(IntantTextActivity.this, NextActivity.class);
intent.putExtras(b);
startActivity(intent);
break;
default:
break;
}
}
}
在第二个Activity中获取Bundle中封装的。通过Key值获取Value值。
package com.fruit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.*;
public class NextActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
String str_username =getIntent().getExtras().getString("username");
String str_password = getIntent().getExtras().getString("password");
TextView user = (TextView)this.findViewById(R.id.user);
TextView pass = (TextView)this.findViewById(R.id.pass);
user.setText("用户名:"+str_username);
pass.setText("密码:"+str_password);
}
}
主页面配置文件:main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="用户名称:"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<EditText
android:text=""
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
<TextView
android:text="用户密码:"
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></TextView>
<EditText
android:text=""
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
></EditText>
<Button
android:text="登陆"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
另外一个页面配置文件:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView "
android:id="@+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="@+id/pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></TextView>
</LinearLayout>
总配置文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fruit"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".IntantTextActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="NextActivity" >
</activity>
</application>
</manifest>
运行页面
跳转到另外一个Activity
- Android 页面间传值(多个数据)
- angularjs 多个页面共享数据
- 09、多个页面共享一套数据
- Android底部菜单(Fragment控制切换多个页面)
- android多个页面滑动视图实现
- android:多个EditText页面滑动实现
- struts向页面传递多个json数据
- android获取数据加载页面(loadingmanager)
- Android多个APK共享数据(Shared User ID)
- Android多个APK共享数据(Shared User ID)
- 【android】关于多个activity页面跳转,跳过中间页面返回前边页面传值
- Android 多个APK共享数据
- android 视图设置多个setTag数据
- Android在多个Activity共享数据
- Android 多个APK数据共享
- Android 多个APK数据共享
- Android Wear Preview- 为通知添加多个页面(Adding Pages to a Notification)
- Android基础之使用Fragment控制切换多个页面(三)
- Linux-2.6.32.2内核在mini2440上的移植(十)---配置USB外设
- Linux-2.6.32.2内核在mini2440上的移植(十一)---移植SD卡驱动
- Linux-2.6.32.2内核在mini2440上的移植(十二)---移植I2C EEPROM驱动
- oracle的dual
- Web站点搭建过程(linux环境配置)
- Android 页面间传值(多个数据)
- Linux-2.6.32.2内核在mini2440上的移植(十三)---移植UDA1341音频驱动
- 智能ABC之备忘
- Linux-2.6.32.2内核在mini2440上的移植(十四)---移植看门狗驱动
- Linux-2.6.32.2内核在mini2440上的移植(十五)---移植LED驱动
- Linux-2.6.32.2内核在mini2440上的移植(十六)---基于中断的按键驱动移植
- 自己动手三步学会国产手机安装QQ,飞信……
- AJAX三级联动
- 超出打开游标的最大数 问题