android初步实现Activity之间的跳转和数据传递
来源:互联网 发布:java有参构造方法示例 编辑:程序博客网 时间:2024/05/16 15:47
第一个Activity
package com.example.activity01;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
class MyButtonListener implements OnClickListener{
public void onClick(View v) {
// TODO Auto-generated method stub
//生成一个intent 对象
Intent intent=new Intent();
intent.setClass(MainActivity.this, OtherActivity.class);
intent.putExtra("testIntent", "123");
intent.putExtra("你妹","你妹的");
MainActivity.this.startActivity(intent);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView myTextView=(TextView)findViewById(R.id.myTestView);
Button myButton=(Button)findViewById(R.id.myButton);
myTextView.setText("我的第一个文本");
myButton.setText("我的第一个按钮"+"\n"+"test");
myButton.setOnClickListener(new MyButtonListener());
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
接受数据的Activity
package com.example.activity01;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
public class OtherActivity extends Activity{
private TextView myText2View=null;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent=getIntent();
String value=intent.getStringExtra("testIntent");
String value2=intent.getStringExtra("你妹");
myText2View=(TextView)findViewById(R.id.myText2View);
myText2View.setText(value);
myText2View.setText(value2);
}
}
第一个的布局
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/myTestView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
第二个的布局
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/myText2View"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Manifest注册文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activity01"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.activity01.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="com.example.activity01.OtherActivity"
android:label="@string/other"
android:theme="@android:style/Theme.Dialog"
/>
</application>
</manifest>
- android初步实现Activity之间的跳转和数据传递
- 实现2个Activity之间跳转及数据的传递
- Activity之间跳转和传递数据
- activity之间的跳转及传递数据
- Activity之间的跳转以及数据传递
- Activity之间的跳转以及数据传递
- activity之间的跳转与数据传递
- Android:Activity之间跳转和参数传递
- Android 使用Intent实现Activity跳转和数据传递
- Android中Fragment之间的跳转和数据的传递
- 记android学习之路----Activity(4)----Activity之间的跳转与数据传递
- Android fragment和activity之间的数据传递交互
- Android Activity、Fragment之间的数据传递和返回
- Android中Activity之间的数据传递和Intent使用
- Android中Activity之间的数据传递和Intent使用
- Android-Activity的基本介绍和页面之间数据传递
- Activity的跳转和传递数据
- 应用之间的跳转和数据传递
- 企业贡献开源,其背后的战略动机是什么?
- 图的遍历-BFS
- win7下安装IIS7.0及部署VS2010 ASP.NET程序网站的相关问题
- 莫名在苦恼
- 杨澜访谈录:花开花落的王学圻
- android初步实现Activity之间的跳转和数据传递
- hdu-1850 Being a Good Boy in Spring Festival
- nginx Windows版使用说明
- python再学习1
- 数据挖掘笔记-关联规则-FPGrowth-简单实现
- 对ZigBee地址的理解
- 一些学习资源分享
- 主动退出iphone应用程序的一种方法
- 跳跃表(skip list) 的实现