Android作业-数据传递

//xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="50dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="24sp"
            android:text="姓名:"/>
        <EditText
            android:id="@+id/et_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入姓名"
            android:inputType="text" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="30dp"
        android:paddingBottom="30dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="24sp"
            android:text="年龄:"/>
        <EditText
            android:id="@+id/et_pwd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入年龄"
            android:inputType="textPassword" />
    </LinearLayout>
    <Button
        android:id="@+id/login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="进入"/>

</LinearLayout>
//xml_2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical"
    tools:context=".MainActivity2">

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="20dp"
        android:textSize="26sp"
        android:text="姓名"/>


    <TextView
        android:id="@+id/tv_age2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="26sp"
        android:paddingTop="60dp"
        android:text="年龄"/>
        android:text="年龄"/>

</LinearLayout>
//MainActivity2
package com.lixin.day05;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

   private TextView tv_name;
    private  TextView tv_age2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

       Intent intent = getIntent();

        String name = intent.getStringExtra("name");
        String age2 = intent.getStringExtra("pwd");

        tv_name = (TextView) findViewById(R.id.tv_name);
       tv_age2 = (TextView) findViewById(R.id.tv_age2);

       tv_name.setText("恭喜您"+name+"来到这个世界");
        tv_age2.setText(age2+"年");}}
//mainactivity
package com.lixin.day05;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    private EditText et_pwd;
    private  EditText et_name;
    private Button login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et_name = (EditText) findViewById(R.id.et_name);
        et_pwd = (EditText) findViewById(R.id.et_pwd);
        login = (Button) findViewById(R.id.login);

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                passDate();
            }
        });
    }
    //数据传递
    public void passDate(){
        //创建Intent对象,启动第二个界面
        Intent intent = new Intent(this,MainActivity2.class);
        //(需要传递的数据)
        intent.putExtra("name",et_name.getText().toString().trim());
        intent.putExtra("pwd",et_pwd.getText().toString().trim());
        startActivity(intent);
    }
}
//manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lixin.day05">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Day05">
        <activity
            android:name=".MainActivity2"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.lixin.action.MainActivity2"></action>
                <category android:name="android.intent.category.DEFAULT"></category>
            </intent-filter>
    </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity3" />
    </application>

</manifest>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要实现一个作业功能的源码,首先需要明确这个功能的具体需求。比如,是老师发布作业、学生提交作业并打分、作业的截止日期等等。接下来,可以采用MVC(Model-View-Controller)架构来设计程序,将不同的功能分别放在不同的类中。 模型层(Model)可以将数据存储在数据库中,包括学生信息、作业内容、分数等。可以使用SQLite或者Room来进行数据库的操作。 视图层(View)则负责展示数据和接收用户的操作,比如老师发布作业的界面、学生提交作业的界面、显示作业列表和分数的界面等。UI可以采用XML布局来进行设计,通过findViewById()方法获取相关控件并设置相应的监听器。 控制器层(Controller)则是连接模型层和视图层的桥梁,负责处理各种逻辑和业务逻辑,比如用户提交作业后如何保存到数据库、如何判断作业是否在截止日期前提交等。 实现作业功能的源码需要考虑到代码的可重用性和可扩展性。可以将一些通用的类(如数据库的操作类)封装起来,方便其他模块调用。同时,在代码中加入注释和文档,方便其他开发人员理解和修改。 总体来说,实现作业功能的源码需要对Android Studio和MVC架构都有一定的了解和掌握,还需要积累一定的编程经验和技巧。 ### 回答2: Android Studio实现作业功能的源码具体实现方法会根据实际的需求和功能而有所不同,但是一般而言,可以参考下面的步骤和代码实现: 1. 创建一个Activity用于展示作业列表,并在布局文件中添加一个ListView或RecyclerView。 2. 创建一个作业实体类,该实体类可以包括标题、内容、截止时间等信息,根据实际需求添加相应的属性。 3. 创建一个作业数据管理类,可以使用SQLite数据库或其他方式实现数据的增删改查操作。在该类中定义获取作业列表、添加作业、删除作业等方法,用于与Activity交互。 4. 在作业列表Activity中初始化数据管理类,获取作业列表,并将作业列表展示在ListView或RecyclerView中。 5. 当用户点击作业列表的某个作业时,跳转到作业详情页面。创建一个作业详情Activity,展示作业的详细信息,并提供修改作业、删除作业等功能。 6. 在作业详情Activity中可以通过Intent传递作业实体类对象到编辑作业页面。创建一个编辑作业Activity,用于编辑作业的信息,包括标题、内容、截止时间等。 7. 编辑作业Activity中可以将作业的信息保存到数据库中,并返回作业详情页面,同时更新作业列表页面的作业信息。 8. 在作业详情Activity中,可以通过对话框或其他方式提供删除作业的操作。删除作业时,需要将作业数据库中删除,并返回到作业列表页面,同时更新作业列表的展示。 9. 可以根据实际需求添加其他功能,如作业提醒、作业分享等。 以上是Android Studio实现作业功能的源码实现步骤及代码示例,具体实现方式还需要根据实际需求进行相应的调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值