zoukankan      html  css  js  c++  java
  • activity带数据跳转

    MainActivity
    package com.example.myapplication;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    import org.w3c.dom.Text;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.login);
        }
    
           public void login(View view){
               EditText id = (EditText) findViewById(R.id.edit1);
               String s = id.getText().toString();
               Intent intent=new Intent();
               intent.setClass(MainActivity.this, TestActivity.class);
               intent.putExtra("id",s);
               startActivity(intent);
           }
    
    }
    TestActivity
    package com.example.myapplication;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.TextView;
    
    public class TestActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test);
            TextView t = (TextView)findViewById(R.id.text);
            Intent intent = this.getIntent();
    
            String id = intent.getStringExtra("id");
            System.out.println(intent.getStringExtra("id"));
            t.setText(id);
        }
    }
    activity_main
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    activity_test
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    login
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""></TextView>
        <ImageView
            android:id="@+id/photo"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/ic_launcher_background"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="200dp"
            android:layout_marginBottom="30dp"></ImageView>
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/photo"
            android:maxLength="15"
            android:layout_marginTop="13dp"
            android:text="账号:"/>
        <EditText
            android:id="@+id/edit1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/photo"
            android:layout_toRightOf="@id/textView1"
            android:hint="请输入您的账号"></EditText>
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView1"
            android:maxLength="20"
            android:layout_marginTop="25dp"
            android:text="密码:" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView1"
            android:layout_toRightOf="@id/textView2"
            android:layout_marginTop="10dp"
            android:hint="请输入您的密码"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button"
            android:text="登录"
            android:textColor="#478595"
            android:layout_below="@id/textView2"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="120dp"
            android:layout_centerHorizontal="true"
            android:onClick="login">
        </Button>
    
    </RelativeLayout>
  • 相关阅读:
    UVa OJ 120
    ACM--string常见用法
    log4j
    总结13.11.9
    Java 动态生成 PDF 文件
    Linux_CentOS-服务器搭建 <七>
    关于dao层的封装和前端分页的结合(文章有点长,耐心点哦)
    Linux_CentOS-服务器搭建 <六>
    Linux_CentOS-服务器搭建 <五> 补充
    JQ获取CKeditor的值
  • 原文地址:https://www.cnblogs.com/iM59/p/14122082.html
Copyright © 2011-2022 走看看