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>
  • 相关阅读:
    H5调用本地摄像头
    zepto和jquery的区别,zepto的不同使用8条小结
    web前端页面性能优化小结
    超赞!聊聊WEB APP、HYBRID APP与NATIVE APP的设计差异
    activemq生产者和消费者的双向通信
    消息队列同步和异步机制
    postman使用教程
    spring boot mybatis sql打印到控制台
    spring boot 整合 mybatis 以及原理
    spring 框架整合mybatis的源码分析
  • 原文地址:https://www.cnblogs.com/WangYYY/p/14023451.html
Copyright © 2011-2022 走看看