Activity跳转中在Activity传值

具体例题在360云盘中http://yunpan.cn/cZNcQw3cf3Spb  访问密码 9d90

清单文件同样需要注册Activity

xml文件
< 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:orientation =  "vertical"
      >

     < TextView
         android:layout_width = "wrap_content"
         android:layout_height = "wrap_content"
         android:layout_gravity = "center_horizontal"
         android:textSize = "28sp"
         android:textColor = "#ff0000"
         android:text = "人品测试"  />
     < EditText
         android:id = "@+id/et_name"
         android:layout_width = "match_parent"
         android:layout_height = "wrap_content"
         android:hint = "请输入姓名:"  />
     < Button     
         android:id = "@+id/test"
         android:layout_width = "match_parent"
         android:layout_height = "wrap_content"
         android:text = "开始测试"  />

</ LinearLayout >
主Java文件
public  class  MainActivity  extends  Activity  implements  OnClickListener {
         private  EditText  et_name  ;
         @Override
         protected  void  onCreate(Bundle savedInstanceState) {
                super .onCreate(savedInstanceState);
              setContentView(R.layout.  activity_main );
       Button test = (Button) findViewById(R.id. test );
         et_name = (EditText) findViewById(R.id.  et_name );
       test.setOnClickListener(  this );
       }
         @Override
         public  void  onClick(View v) {
              String name=  et_name .getText().toString().trim();
                if (TextUtils.isEmpty(name)){
                       new  AlertDialog.Builder( this ).setMessage( "名字不能为空" ).show();
              }
                else {
                     Intent intent =  new Intent(this , ResultActivity.class);
                     intent.putExtra( "name",name);
                     startActivity(intent);
              }
       }
}
副xml文件
<? 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:layout_width =  "wrap_content"
     android:layout_height =  "wrap_content"
     android:textSize =  "28sp"
     android:textColor =  "#ff0000"
     android:text =  "你的人品值"
     android:layout_gravity =  "center_horizontal" />
    < TextView
     android:id = "@+id/tv_result"
     android:layout_width =  "match_parent"
     android:layout_height =  "wrap_content"
     />

    < ProgressBar
        android:id = "@+id/pb_testRP"
        style =  "?android:attr/progressBarStyleHorizontal"
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        android:max="100"  />

</ LinearLayout >
副Java文件
public  class  ResultActivity  extends  Activity {

         @Override
         protected  void  onCreate(Bundle savedInstanceState) {
                //  TODO  Auto-generated method stub
                super .onCreate(savedInstanceState);
              setContentView(R.layout.  result );
              TextView result =(TextView) findViewById(R.id.  tv_result );
              
              Intent intent = getIntent();
              
              String name= intent.getStringExtra( "name");
              
              Random random =  new  Random();
                int  rp = random.nextInt(101);
              
              result.setText(name+  "您的人品值为:"  +rp);
              
              ProgressBar pb = (ProgressBar) findViewById(R.id.  pb_testRP );
              pb.setProgress(rp);
       }
       
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值