Android 页面传参 页面跳转

LoginActivity.java

 

  1. package com.cloud.android;  
  2.   
  3. import android.app.Activity;  
  4. import android.app.AlertDialog;  
  5. import android.app.AlertDialog.Builder;  
  6. import android.content.DialogInterface;  
  7. import android.content.Intent;  
  8. import android.os.Bundle;  
  9. import android.view.View;  
  10. import android.view.View.OnClickListener;  
  11. import android.widget.Button;  
  12. import android.widget.EditText;  
  13.   
  14. public class LoginActivity extends Activity {  
  15.     private EditText userNameEditText,pwdEditText;  
  16.     private Button loginBtn,cancelBtn;  
  17.       
  18.     @Override  
  19.     public void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         setContentView(R.layout.login);  
  22.         setTitle("登录");  
  23.         userNameEditText = (EditText) findViewById(R.id.username);  
  24.         pwdEditText = (EditText) findViewById(R.id.password);  
  25.           
  26.         loginBtn = (Button) findViewById(R.id.loginButton);  
  27.         cancelBtn = (Button) findViewById(R.id.calcelButton);  
  28.   
  29.         cancelBtn.setOnClickListener(new OnClickListener() {  
  30.             public void onClick(View v) {  
  31.                 exitAlert("真的要退出吗?");  
  32.             }  
  33.         });  
  34.           
  35.           
  36.         loginBtn.setOnClickListener(new OnClickListener() {  
  37.             public void onClick(View v) {  
  38.                 String username = userNameEditText.getText().toString();  
  39.                 String password = pwdEditText.getText().toString();  
  40.                 //跳转  
  41.                 Intent intent = new Intent(LoginActivity.this, ResultActivity.class);  
  42.                 intent.putExtra("name", username);  
  43.                 intent.putExtra("pwd", password);  
  44.                 startActivity(intent);  
  45.             }  
  46.         });  
  47.     }  
  48.     /** 
  49.      * 退出提示确认框 
  50.      * @param msg 
  51.      */  
  52.     private void exitAlert(String msg) {  
  53.         Builder builder = new Builder(this);  
  54.         builder.setMessage(msg)  
  55.         .setCancelable(false)  
  56.         .setPositiveButton("确定"new DialogInterface.OnClickListener() {  
  57.             public void onClick(DialogInterface dialog, int which) {  
  58.                 finish();  
  59.             }  
  60.         }).setNegativeButton("取消"new DialogInterface.OnClickListener() {  
  61.             public void onClick(DialogInterface dialog, int which) {  
  62.                 return;  
  63.             }  
  64.         });  
  65.         AlertDialog alert = builder.create();  
  66.         alert.show();  
  67. //      builder.show();  
  68.     }  
  69. }  


 

 

 

ResultActivity.java

 

  1. package com.cloud.android;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.widget.TextView;  
  7.   
  8. public class ResultActivity extends Activity {  
  9.     private TextView usernameTextView,passwordTextView;  
  10.     @Override  
  11.     protected void onCreate(Bundle savedInstanceState) {  
  12.         super.onCreate(savedInstanceState);  
  13.         setContentView(R.layout.result);  
  14.           
  15.         usernameTextView = (TextView) findViewById(R.id.UserNameTextView);  
  16.         passwordTextView = (TextView) findViewById(R.id.PassWordTextView);  
  17.           
  18.         Intent intent = getIntent();  
  19.         String name = intent.getStringExtra("name");  
  20.         String pwd = intent.getStringExtra("pwd");  
  21.           
  22.         usernameTextView.setText(name);  
  23.         passwordTextView.setText(pwd);  
  24.           
  25.     }  
  26. }  


 

 

 

layout布局文件 login.xml

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.    <TableLayout   
  8.        android:layout_width="fill_parent"  
  9.        android:layout_height="fill_parent"  
  10.        android:stretchColumns="1">  
  11.        <TableRow>             
  12.             <TextView  
  13.                 android:id="@+id/TextView"  
  14.                 android:layout_width="fill_parent"  
  15.                 android:layout_height="wrap_content"  
  16.                 android:text="用户名:" />  
  17.       
  18.             <EditText   
  19.                 android:id="@+id/username"  
  20.                 android:layout_width="fill_parent"  
  21.                 android:layout_height="wrap_content" />  
  22.        </TableRow>  
  23.         <TableRow>             
  24.             <TextView  
  25.                 android:id="@+id/TextView"  
  26.                 android:layout_width="fill_parent"  
  27.                 android:layout_height="wrap_content"  
  28.                 android:text="密码:"/>  
  29.       
  30.             <EditText   
  31.                 android:id="@+id/password"  
  32.                 android:layout_width="fill_parent"  
  33.                 android:layout_height="wrap_content"  
  34.                 android:password="true"  />  
  35.        </TableRow>  
  36.         <TableRow android:gravity="right">             
  37.             <Button  
  38.                 android:id="@+id/loginButton"  
  39.                 android:layout_width="wrap_content"  
  40.                 android:layout_height="wrap_content"  
  41.                 android:text="登录" />  
  42.       
  43.             <Button   
  44.                 android:id="@+id/calcelButton"  
  45.                 android:layout_width="wrap_content"  
  46.                 android:layout_height="wrap_content"  
  47.                 android:text="取消" />  
  48.        </TableRow>  
  49.    </TableLayout>  
  50. </LinearLayout>  


 

 

result.xml

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.      <TextView  
  8.             android:id="@+id/UserNameTextView"  
  9.             android:layout_width="wrap_content"  
  10.             android:layout_height="wrap_content" />  
  11.        
  12.      <TextView  
  13.             android:id="@+id/PassWordTextView"  
  14.             android:layout_width="wrap_content"  
  15.             android:layout_height="wrap_content" />  
  16.   
  17. </LinearLayout>  


 

 

AndroidManifest.xml

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.cloud.android"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.   
  7.     <uses-sdk android:minSdkVersion="10" />  
  8.   
  9.     <application  
  10.         android:icon="@drawable/ic_launcher"  
  11.         android:label="@string/app_name" >  
  12.         <activity  
  13.             android:label="@string/app_name"  
  14.             android:name=".LoginActivity" >  
  15.             <intent-filter >  
  16.                 <action android:name="android.intent.action.MAIN" />  
  17.   
  18.                 <category android:name="android.intent.category.LAUNCHER" />  
  19.             </intent-filter>  
  20.         </activity>  
  21.           
  22.             <activity android:name=".ResultActivity"></activity>  
  23.     </application>  
  24.   
  25. </manifest> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值