<?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);
}
}
人品计算器
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- packagework11; importjava.io.*; importjava.net.*; public ...