久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3412|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

安卓體重計算器java源程序 使用Intent在Activity間傳輸數(shù)據(jù)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:856808 發(fā)表于 2020-12-15 20:25 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最后由 dori 于 2020-12-18 23:10 編輯

完成一個體重計算器的應(yīng)用程序開發(fā)。
           

MainActivity文件:
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button bn=findViewById(R.id.bn);
        final RadioGroup male=findViewById(R.id.male);

        //綁定監(jiān)視器
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText et = findViewById(R.id.editText);
                Boolean sex = male.getCheckedRadioButtonId()==R.id.rb1?true:false;//true為男,false為女
                String height = et.getText().toString();
                //創(chuàng)建Intent
                Intent intent = new Intent(MainActivity.this, Activity.class);
                intent.putExtra("sex", sex);
                intent.putExtra("height", height);
                startActivity(intent);
            }
        });
    }
}
Activity.java文件:

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Activity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);

        TextView tv1 = findViewById(R.id.gender);
        TextView tv2 = findViewById(R.id.height);
        TextView tv3 = findViewById(R.id.weight);

        //獲得intent
        Intent intent = getIntent();
        //獲得性別和身高信息
        Boolean sex =intent.getBooleanExtra("sex", true);
        Integer height = Integer.parseInt(intent.getStringExtra("height"));
        if (sex) //男
        {
            tv1.setText("你是一名男性");
            tv2.setText("你的身高是" + height + "厘米");
            Double weight = (height - 80) * 0.7;
            tv3.setText("你的標(biāo)準(zhǔn)體重是" + weight + "公斤");
        } else {
            tv1.setText("你是一名女性");
            tv2.setText("你的身高是" + height + "厘米");
            Double weight = (height - 70) * 0.6;
            tv3.setText("你的標(biāo)準(zhǔn)體重是" + weight + "公斤");
        }
    }
}
activity_main.xml文件:

<?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">

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="-148dp">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="40dp" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="計算標(biāo)準(zhǔn)體重"
            android:textSize="30sp" />

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="73dp"
                android:layout_height="wrap_content"
                android:text="性別:"
                android:textSize="20sp" />

            <RadioGroup
                android:id="@+id/male"
                android:layout_width="337dp"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/rb1"
                    android:layout_width="142dp"
                    android:layout_height="match_parent"
                    android:text="男性"
                    android:textSize="20sp" />

                <RadioButton
                    android:id="@+id/rb2"
                    android:layout_width="147dp"
                    android:layout_height="wrap_content"
                    android:text="女性"
                    android:textSize="20sp" />

            </RadioGroup>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/height"
                android:layout_width="73dp"
                android:layout_height="wrap_content"
                android:text="身高:"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/editText"
                android:layout_width="175dp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="number"
                android:textColor="#E91E63" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="72dp"
                android:layout_height="wrap_content"
                android:text="cm"
                android:textSize="20sp" />
        </TableRow>

        <TableRow
            android:layout_width="400dp"
            android:layout_height="60dp">

            <TextView
                android:id="@+id/textView6"
                android:layout_width="314dp"
                android:layout_height="wrap_content" />

            <Button
                android:id="@+id/bn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="計算"
                android:textSize="25sp" />
        </TableRow>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
result.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView10"
        android:layout_width="match_parent"
        android:layout_height="158dp" />

    <TextView
        android:id="@+id/gender"
        android:layout_width="match_parent"
        android:layout_height="52dp" />

    <TextView
        android:id="@+id/height"
        android:layout_width="match_parent"
        android:layout_height="52dp" />

    <TextView
        android:id="@+id/weight"
        android:layout_width="match_parent"
        android:layout_height="52dp" />
</LinearLayout>

使用Intent在Activity間傳輸數(shù)據(jù).rar (8.52 MB, 下載次數(shù): 5)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 9久9久 | 国产精品亚洲精品日韩已方 | 亚洲国产午夜 | 91不卡 | 欧美精品一区二区三区在线播放 | www.三级| 欧美高清成人 | 久久久久成人精品免费播放动漫 | 成人免费观看男女羞羞视频 | 九九热精品视频 | 男女羞羞视频免费 | 青草青草久热精品视频在线观看 | 九九热免费在线观看 | 国产高清在线 | 日韩免费一二三区 | 99精品国产一区二区三区 | 日韩精品在线一区 | 精品综合久久久 | 久久丝袜| 成人国产精品一级毛片视频毛片 | 成人高清在线 | 免费成人在线网站 | 久久成人免费视频 | 一级在线观看 | 一区在线播放 | 国产成人综合一区二区三区 | 欧洲视频一区 | 第四色影音先锋 | av日韩在线播放 | 国产精品自在线 | 日韩国产欧美一区 | 国产精品电影在线观看 | 亚洲欧美日韩久久久 | 欧美在线一区二区视频 | www亚洲精品 | 精品亚洲一区二区 | 99久久视频 | 国产免费观看一区 | 欧美一区在线看 | 日日夜夜精品视频 | 亚洲成人一区二区三区 |