zoukankan      html  css  js  c++  java
  • Android_2.2_eclips_Bundle简单传参demo

    Bundle简单传参示例

    mainActivity

    package com.gongsi.testbundle;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

    public class TestBundleActivity extends Activity {
    private Button btn;
    private View.OnClickListener c1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //找到button按钮
    btn = (Button)findViewById(R.id.btn);
    //设置按钮监听
    c1 = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent = new Intent();
    intent.setClass(TestBundleActivity.this, Target.class);
    //建立Bundle并put进入不同类型键值对
    Bundle bundle = new Bundle();
    bundle.putString("Data", "ray'blog");
    bundle.putDouble("double", 1.0);
    intent.putExtras(bundle);
    //启动
    startActivity(intent);
    finish();
    }
    };

    btn.setOnClickListener(c1);

    }
    }

    TargetActivity  接收到的bundle的值取出并log打印出来

    package com.gongsi.testbundle;

    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;

    public class Target extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Bundle bundle = getIntent().getExtras();
    String data = bundle.getString("Data");
    double dou = bundle.getDouble("double");
    Log.v("info:","data:"+data+" "+"dou:"+dou);
    }

    }


    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:layout_width="fill_parent"
    android:layout_height
    ="wrap_content"
    android:text
    ="@string/hello"
    />
    <Button
    android:id="@+id/btn"
    android:text
    ="intent.putExtra(bundle)"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    />
    </LinearLayout>

    mainfest主要是增加target Activity

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package
    ="com.gongsi.testbundle"
    android:versionCode
    ="1"
    android:versionName
    ="1.0">
    <uses-sdk android:minSdkVersion="8"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".TestBundleActivity"
    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=".Target"/>
    </application>
    </manifest>




  • 相关阅读:
    easyui validatebox textbox 取值和赋值
    linq中如何在join中指定多个条件
    easyui datagrid 表头固定(垂直滚动条)、列固定(水平滚动条)
    JS Jquery 中 的遍历
    EasyUI datagrid formatter 属性
    基于C#的socket编程的TCP异步实现
    Winform 最小化双击显示,最小化右键退出。退出
    C#中的Invoke
    Socket之listen() receive()
    20210512学习笔记--一直没干啥有用的事儿,最主要还是量变不够,进展过于慢了
  • 原文地址:https://www.cnblogs.com/flyingsir/p/2263746.html
Copyright © 2011-2022 走看看