onActivityResult传值的使用
有时候在群里加入的新人总会喜欢问一些过去的问题 有时候不想回答 是因为回答的次数多了
不回答又打击人的积极性 谁让自己接触的早呢 为了省劲还是把简单的东西作为指导篇吧
多个activity之间的传值 其实就是onActivityResult,然后别忘了还有一个action的问题 就是在主xml中添加自己的action以便于识别,最后次activity别忘了finansh。
Java代码
- public class Wizard extends Activity {
- private TextView step1result, step2result, step3result;
- public static final String INTENT_STEP1 = "com.novoda.STEP1";
- public static final String INTENT_STEP2 = "com.novoda.STEP2";
- public static final String INTENT_STEP3 = "com.novoda.STEP3";
- private static final int STEP1 = 1;
- private static final int STEP2 = 2;
- private static final int STEP3 = 3;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.wizard);
- this.step1result = (TextView)findViewById(R.id.step1result);
- this.step2result = (TextView)findViewById(R.id.step2result);
- this.step3result = (TextView)findViewById(R.id.step3result);
- startActivityForResult(new Intent(Wizard.INTENT_STEP1), STEP1);
- }
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch (requestCode) {
- case STEP1:
- this.step1result.setText(data.getStringExtra("STEP1RESULT"));
- startActivityForResult(new Intent(Wizard.INTENT_STEP2), STEP2);
- break;
- case STEP2:
- this.step2result.setText(data.getStringExtra("STEP2RESULT"));
- startActivityForResult(new Intent(Wizard.INTENT_STEP3), STEP3);
- break;
- case STEP3:
- this.step3result.setText(data.getStringExtra("STEP3RESULT"));
- break;
- }
- }
- }
Java代码
- public class Step1 extends Activity {
-
@Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.step1);
- Button nextStep = (Button)findViewById(R.id.goto2);
- nextStep.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Intent it = new Intent();
- it.putExtra("STEP1RESULT", ((EditText)findViewById(R.id.step1value)).getText()
- .toString());
- setResult(Activity.RESULT_OK, it);
- finish();
- }
- });
- }
- }
后面的step2 step3都是一样的了
然后还有主xml
Java代码"@drawable/icon" android:label="@string/app_name">-
".Wizard" android:label="@string/app_name"> -
-
"android.intent.action.MAIN" /> -
"android.intent.category.LAUNCHER" /> -
".Step1" android:label="Step1"> -
-
"com.novoda.STEP1" /> -
"android.intent.category.DEFAULT" /> -
".Step2" android:label="Step2"> -
-
"com.novoda.STEP2" /> -
"android.intent.category.DEFAULT" /> -
".Step3" android:label="Step3"> -
-
"com.novoda.STEP3" /> -
"android.intent.category.DEFAULT" /> -
"7" />
- Wizard.rar (50.8 KB)
- 下载次数: 555
“onActivityResult传值的使用” 的相关文章
dp,px,pt,sp 的区别 以及dp 和 px 互转
dp = dip : device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。px: pixels(像素). 不同设备显示效果相同,一般我们HVGA代表320x480像…
Android的onCreateOptionsMenu()创建菜单Menu详解
Android一共有三种形式的菜单: 1.选项菜单(optinosMenu) &nbs…
Android 处理屏幕旋转
不加任何旋转屏幕的处理代码的时候,旋转屏幕将会导致系统把当前activity关闭,重新打开。如果只是简单的界面调整,我们可以阻止此问题的发生,屏幕旋转而自己调整屏幕的元素重构。[1].[代码] 首先我们需要修改AndroidMan...…
android 按两次返回键退出
我们可以在很多应用中都能看到按两次返回键退出 , 其实这个功能实现很容易, 下面就是实现的代码 , 把它放到你的程序中你的程序就能按两次返回键退出啦 , 这个功能是为了避免误点而把程序退出了 ,给你的程序...…
Android 使用 adb命令 远程安装apk
./adb devices 列出所有设备…