当前位置: 首页 > news >正文

Android复习代码1-4章


public class RudioButton extends AppCompatActivity {@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_rudio_button);// 找到RadioGroup和TextView的实例RadioGroup radioGroup = findViewById(R.id.radio);TextView tv = findViewById(R.id.tv);// 在radioGroup实例上设置监听器radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {if (checkedId == R.id.girl) {tv.setText("女生");} else {tv.setText("男生");}}});}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><RadioGroupandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/radio"><RadioButtonandroid:id="@+id/girl"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="女"/><RadioButtonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="男"/></RadioGroup><TextViewandroid:layout_width="wrap_content"android:layout_height="match_parent"android:textSize="20sp"android:id="@+id/tv"/></LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><CheckBoxandroid:id="@+id/badminton"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="羽毛球"/><CheckBoxandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/basketball"android:text="篮球"/><CheckBoxandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/pingpang"android:text="乒乓"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/hobby"android:textSize="30sp"/>
</LinearLayout>
package com.example.bok;import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;public class hobby extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {private TextView hobby;private String hobbys ;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.checkbox);CheckBox checkBox1 = findViewById(R.id.badminton);CheckBox checkBox2 =findViewById(R.id.basketball);CheckBox checkBox3 =findViewById(R.id.pingpang);checkBox1.setOnCheckedChangeListener(this);checkBox2.setOnCheckedChangeListener(this);checkBox3.setOnCheckedChangeListener(this);hobby=findViewById(R.id.hobby);hobbys = new String();}@Overridepublic void onCheckedChanged(CompoundButton compoundButton, boolean b) {String motion = compoundButton.getText().toString();if (b){if(!hobbys.contains(motion)){hobbys=hobbys+motion;hobby.setText(hobbys);}}else {if(hobbys.contains(motion)){hobbys=hobbys.replace(motion,"");hobby.setText(hobbys);}}}}

 AndroidManifest.xml中注册Activity启动和关闭activity

    @Overridepublic void onClick(View view) {Intent intent =new Intent(MainActivity.this, jump.class);startActivity(intent);}

 发数据

   public void onClick(View view) {String acc =id.getText().toString();String psd =psw.getText().toString();Intent intent =new Intent(MainActivity.this, jump.class);intent.putExtra("username",acc);intent.putExtra("psw",psd);startActivity(intent);}

接收

public class jump extends AppCompatActivity {@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.jump);Button btn2 = findViewById(R.id.btn2);Intent intent = this.getIntent();String username= intent.getStringExtra("username");String psw = intent.getStringExtra("psw");TextView tv1 = findViewById(R.id.tv1);TextView tv2 = findViewById(R.id.tv2);tv1.setText(username);tv2.setText(psw);btn2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {finish();}});}
}
    @Overridepublic void onClick(View view) {String acc =id.getText().toString();String psd =psw.getText().toString();Bundle bundle = new Bundle();bundle.putString("username",acc);bundle.putString("psw",psd);Intent intent =new Intent(MainActivity.this, jump.class);intent.putExtras(bundle);startActivity(intent);}
        Button btn2 = findViewById(R.id.btn2);Bundle bundle = this.getIntent().getExtras();String username= bundle.getString("username");String psw = bundle.getString("psw");

public class FR extends Fragment {@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {View v = inflater.inflate(R.layout.activity_main,container,false);return v;}
}

 

http://www.lryc.cn/news/493943.html

相关文章:

  • 【问题】webdriver.Chrome()设置参数executable_path报不存在
  • win10系统安装docker-desktop
  • 小程序-基于java+SpringBoot+Vue的乡村研学旅行平台设计与实现
  • 组件A底部栏(position: fixed )事件使用$emit更新内容失败bug解决
  • 数据结构——排序第三幕(深究快排(非递归实现)、快排的优化、内省排序,排序总结)超详细!!!!
  • C++的类功能整合
  • 《String类》
  • 【docker】docker的起源与容器的由来、docker容器的隔离机制
  • Window 安装 Nginx
  • replace (regexp|substr, newSubstr|function)替换字符串中的指定部分
  • 【ROS2】Ubuntu22.04安装ROS humble
  • cesium 3Dtiles变量
  • 配置泛微e9后端开发环境
  • 【Stable Diffusion】安装教程
  • USB Type-C一线通扩展屏:多场景应用,重塑高效办公与极致娱乐体验
  • 【力扣】541.反转字符串2
  • 什么是防抖与节流
  • springboot vue 开源 会员收银系统 (12)购物车关联服务人员 订单计算提成
  • FFmpeg 推流给 FreeSWITCH
  • .npmrc文件的用途
  • C++游戏开发入门:如何从零开始实现自己的游戏项目?
  • Redis设计与实现第16章 -- Sentinel 总结1(初始化、主从服务器获取信息、发送信息、接收信息)
  • Windows10+VirtualBox+Ubuntu:安装虚拟机VirtualBox,虚拟机中安装Ubuntu
  • Torchtune在AMD GPU上的使用指南:利用多GPU能力进行LLM微调与扩展
  • C底层 函数栈帧
  • 【模块一】kubernetes容器编排进阶业务容器化案例
  • 可视化建模以及UML期末复习篇----相关软件安装
  • Appflyer记录卸载事件
  • JDK17 AbstractQueuedSynchronizer 二 条件队列
  • 8 设计模式之简单工厂模式