婚姻建议APP示范例


activity_main.xml:

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/promptSex"/>
    <EditText
        android:id="@+id/edtSex"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/promptAge"/>
    <EditText
        android:id="@+id/edtAge"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:text=""
        />

    <Button
        android:id="@+id/btnDoSug"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/promptBtnDoSug"
        />
    <TextView
        android:id="@+id/txtResult"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/sugResult"
        />
</LinearLayout>

mian:

package com.example.administrator.excample2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class main extends AppCompatActivity {
    private Button btnDoSug;
    private EditText edtSex,edtAge;
    private TextView txtResult;

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

    }

    private void stupViewComponent(){
        btnDoSug=(Button)findViewById(R.id.btnDoSug);
        edtAge=(EditText)findViewById(R.id.edtAge);
        edtSex=(EditText)findViewById(R.id.edtSex);
        txtResult=(TextView)findViewById(R.id.txtResult);

        btnDoSug.setOnClickListener(btnDoSugOnclick);


    }

    private Button.OnClickListener btnDoSugOnclick= new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            String strSex=edtSex.getText().toString();
            int iAge=Integer.parseInt(edtAge.getText().toString());
            String strSug=getString(R.string.sugResult);
            if(strSex.equals(getString(R.string.sexMale)))
                if(iAge<28)
                    strSug+=getString(R.string.sugNotHurry);
                else if (iAge>33)
                    strSug+=getString(R.string.sugGetMarried);
                else
                    strSug+=getString(R.string.sugFindCounple);
            else
                if (iAge<25)
                    strSug+=getString(R.string.sugNotHurry);
                else if (iAge>30)
                    strSug+=getString(R.string.sugGetMarried);
                else
                    strSug+=getString(R.string.sugFindCounple);
            txtResult.setText(strSug);

        }
    };

}
strings.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <string name="app_name">婚姻建议</string>
    <string name="promptSex">性别:</string>
    <string name="promptAge">年龄:</string>
    <string name="promptBtnDoSug">婚姻建议</string>
    <string name="sugResult">结果:</string>
    <string name="sugNotHurry">还不急。</string>
    <string name="sugGetMarried">赶快结婚!</string>
    <string name="sugFindCounple">开始找对象</string>
    <string name="sexMale"></string>


</resources>


结果:


出现问题:

1、在AVD中输入文字的时候没有中文输入

2、将app-debug.apk安装在手机上的时候,输入数字点击婚姻建议的时候,直接关闭APP,运行结果与在AVD中的运行不一致,总的说是失败的。

参考书籍代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值