zoukankan      html  css  js  c++  java
  • 跳转与数据传递

     1 package com.example.myapplication;
     2 
     3 import androidx.appcompat.app.AppCompatActivity;
     4 
     5 import android.app.Activity;
     6 import android.content.Intent;
     7 import android.os.Bundle;
     8 import android.view.View;
     9 import android.widget.Button;
    10 import android.widget.EditText;
    11 import android.widget.TextView;
    12 
    13 import org.w3c.dom.Text;
    14 
    15 public class MainActivity extends Activity {
    16 
    17     @Override
    18     protected void onCreate(Bundle savedInstanceState) {
    19         super.onCreate(savedInstanceState);
    20         setContentView(R.layout.login);
    21     }
    22 
    23        public void login(View view){
    24            EditText id = (EditText) findViewById(R.id.edit1);
    25            String s = id.getText().toString();
    26            Intent intent=new Intent();
    27            intent.setClass(MainActivity.this, TestActivity.class);
    28            intent.putExtra("id",s);
    29            startActivity(intent);
    30        }
    31 
    32 }
     1 package com.example.myapplication;
     2 
     3 import androidx.appcompat.app.AppCompatActivity;
     4 
     5 import android.content.Intent;
     6 import android.os.Bundle;
     7 import android.view.View;
     8 import android.widget.TextView;
     9 
    10 public class TestActivity extends AppCompatActivity {
    11 
    12     @Override
    13     protected void onCreate(Bundle savedInstanceState) {
    14         super.onCreate(savedInstanceState);
    15         setContentView(R.layout.activity_test);
    16         TextView t = (TextView)findViewById(R.id.text);
    17         Intent intent = this.getIntent();
    18 
    19         String id = intent.getStringExtra("id");
    20         System.out.println(intent.getStringExtra("id"));
    21         t.setText(id);
    22     }
    23 }
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     xmlns:app="http://schemas.android.com/apk/res-auto"
     4     xmlns:tools="http://schemas.android.com/tools"
     5     android:layout_width="match_parent"
     6     android:layout_height="match_parent"
     7     tools:context=".MainActivity">
     8 
     9     <TextView
    10         android:layout_width="wrap_content"
    11         android:layout_height="wrap_content"
    12         android:text="Hello World!"
    13         app:layout_constraintBottom_toBottomOf="parent"
    14         app:layout_constraintLeft_toLeftOf="parent"
    15         app:layout_constraintRight_toRightOf="parent"
    16         app:layout_constraintTop_toTopOf="parent" />
    17 
    18 </androidx.constraintlayout.widget.ConstraintLayout>
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:orientation="vertical" android:layout_width="match_parent"
     4     android:layout_height="match_parent">
     5 <TextView
     6     android:layout_width="wrap_content"
     7     android:layout_height="wrap_content"
     8     android:text=""></TextView>
     9     <ImageView
    10         android:id="@+id/photo"
    11         android:layout_width="80dp"
    12         android:layout_height="80dp"
    13         android:src="@drawable/ic_launcher_background"
    14         android:layout_centerHorizontal="true"
    15         android:layout_marginTop="200dp"
    16         android:layout_marginBottom="30dp"></ImageView>
    17     <TextView
    18         android:id="@+id/textView1"
    19         android:layout_width="wrap_content"
    20         android:layout_height="wrap_content"
    21         android:layout_below="@id/photo"
    22         android:maxLength="15"
    23         android:layout_marginTop="13dp"
    24         android:text="账号:"/>
    25     <EditText
    26         android:id="@+id/edit1"
    27         android:layout_width="match_parent"
    28         android:layout_height="wrap_content"
    29         android:layout_below="@id/photo"
    30         android:layout_toRightOf="@id/textView1"
    31         android:hint="请输入您的账号"></EditText>
    32     <TextView
    33         android:id="@+id/textView2"
    34         android:layout_width="wrap_content"
    35         android:layout_height="wrap_content"
    36         android:layout_below="@id/textView1"
    37         android:maxLength="20"
    38         android:layout_marginTop="25dp"
    39         android:text="密码:" />
    40     <EditText
    41         android:layout_width="match_parent"
    42         android:layout_height="wrap_content"
    43         android:layout_below="@id/textView1"
    44         android:layout_toRightOf="@id/textView2"
    45         android:layout_marginTop="10dp"
    46         android:hint="请输入您的密码"/>
    47     <Button
    48         android:layout_width="wrap_content"
    49         android:layout_height="wrap_content"
    50         android:id="@+id/button"
    51         android:text="登录"
    52         android:textColor="#478595"
    53         android:layout_below="@id/textView2"
    54         android:layout_marginTop="20dp"
    55         android:layout_marginLeft="120dp"
    56         android:layout_centerHorizontal="true"
    57         android:onClick="login">
    58     </Button>
    59 
    60 </RelativeLayout>
  • 相关阅读:
    我经历的IT公司面试及离职感受(转)
    一个优异的经理人,碰到糟糕的企业,最后往往存在的还是那间糟糕的企业(转)
    Android TextView和EditText属性详解
    Android EditText控件行尾为表情时的BUG
    Android安全问题 抢先拦截短信
    Android安全问题 抢先开机启动
    Android安全问题 抢先接收广播
    Android安全问题 抢先接收广播
    Android 监听EditView中的文本改变事件
    Android EditText中插入图片并响应点击事件
  • 原文地址:https://www.cnblogs.com/WangYYY/p/14023451.html
Copyright © 2011-2022 走看看