美文网首页
人品计算器

人品计算器

作者: pengtuanyuan | 来源:发表于2016-11-16 22:24 被阅读0次
<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.pengtuanyuan.personcalculate.MainActivity">

    <EditText
        android:id="@+id/ed_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="请输入姓名"/>


    <RadioGroup
        android:layout_marginTop="20dp"
        android:id="@+id/rdg_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rb_female"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="女"/>

        <RadioButton
            android:layout_marginLeft="20dp"
            android:id="@+id/rb_male"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="男"/>

        <RadioButton
            android:layout_marginLeft="20dp"
            android:id="@+id/rb_other"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="人妖"/>

    </RadioGroup>

    <Button
        android:layout_marginTop="20dp"
        android:id="@+id/bt_calculate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="计算"/>
</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">

    <TextView
        android:id="@+id/resultName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Union"/>

    <TextView
        android:id="@+id/resultSex"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="男"/>
    <TextView
        android:id="@+id/resultContext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="你的人品好的不得了"/>

</LinearLayout>
--------------------------------------------------------

package com.example.pengtuanyuan.personcalculate;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText ed_name;
    private RadioGroup rdg_group;
    private Button bt_calculate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ed_name = (EditText) findViewById(R.id.ed_name);
        rdg_group = (RadioGroup) findViewById(R.id.rdg_group);
        bt_calculate = (Button) findViewById(R.id.bt_calculate);

        bt_calculate.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {


        String name = ed_name.getText().toString().trim();
        if (TextUtils.isEmpty(name)) {
            Toast.makeText(getApplicationContext(), "用户名不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        int checkedRadioButtonId = rdg_group.getCheckedRadioButtonId();
        int sex = 0;

        switch (checkedRadioButtonId) {
            case R.id.rb_female:
                sex = 1;
                break;
            case R.id.rb_male:
                sex = 2;
                break;
            case R.id.rb_other:
                sex = 3;
                break;
            default:
                break;
        }
        if (sex == 0) {

            Toast.makeText(getApplicationContext(), "亲,请你要选择性别喔", Toast.LENGTH_SHORT).show();
        }
        Intent intent=new Intent(this,ResultActivity.class);
        startActivity(intent);

    }
}
--------------------------------------------------------------
package com.example.pengtuanyuan.personcalculate;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class ResultActivity extends AppCompatActivity {

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

        TextView resultName= (TextView) findViewById(R.id.resultName);
        TextView resultSex= (TextView) findViewById(R.id.resultSex);
        TextView resultContext= (TextView) findViewById(R.id.resultContext);
    }
}



相关文章

  • 人品计算器

  • iOS简单项目 — 计算器

    计算器所需求功能 计算器所用模式:MVC计算器所用语言:Swift计算器所参考课程:斯坦福 第一步:构造计算器界面...

  • 【敲黑板】考试计算器技巧

    方案一 普通计算器+科学计算器(让带计算器) 方案二 搜狗输入法V+计算大法(不让带计算器) 快捷操作 加:+ ...

  • 2018-11-11

    html部分 计算器 计算器 × □ - CE ...

  • 房贷计算器

    最近房产版升级,需要重新制作房贷计算器的功能,主要参考了 房天下房贷计算器和安居客房贷计算器,两大平台的计算器。 ...

  • 2018-11-01for/while/计算器

    计算器 计算器 window.onload = function(){va...

  • 使用WGIS的字段计算器

    WGIS的字段计算器(Field Calculator)跟其他桌面GIS软件的字段计算器类似,计算器的规则遵循Ja...

  • C#第一次作业02

    #作业要求 乘法计算器 #程序 namespace 乘法计算器 { public partial class ...

  • 项目-HTML,CSS,JavaScript计算器

    整个计算器分为四部分:1.构建计算器的框架;2.为计算器添加样式;3.实现计算、回删、清零功能;4.为计算器添加日...

  • ???

    2019.6.28 昨天考试摁计算器,9999999的999999次方计算器算不出来。 看来计算器也不是万能的。 ...

网友评论

      本文标题:人品计算器

      本文链接:https://www.haomeiwen.com/subject/dmarpttx.html