Android开发实用小工具十一——亲戚称呼计算器


前言

亲戚称呼计算器的开发与实现。


一、效果展示

亲戚称呼计算器的开发与实现亲戚称呼计算器的开发与实现

二、代码

准备工作与我开发的另一个小工具(长度转换工具)所用一致,详情请看我上一篇文章。
链接: Android开发实用小工具二——长度转换工具

1.样式布局

res/layout/activity_relatives_call_calculator.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffe9ecf1"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#FFFFFFFF">

        <ImageView
            android:id="@+id/iv_back"
            android:layout_width="40dp"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:padding="10dp"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_back" />

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:textColor="#ff000000"
            android:textSize="17sp"
            android:text="亲戚称呼计算器" />

    </RelativeLayout>

    <TextView
        android:id="@+id/tv_input"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:background="#00000000"
        android:gravity="right|bottom"
        android:padding="5dp"
        android:textColor="#FF000000"
        android:textSize="30sp"
        android:text="我" />

    <TextView
        android:id="@+id/tv_results"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="70dp"
        android:layout_marginRight="10dp"
        android:background="#00000000"
        android:gravity="right|center"
        android:padding="5dp"
        android:textColor="#FF959595"
        android:textSize="20sp"
        tools:text="爸爸/父亲" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape_module"
        android:orientation="vertical"
        android:padding="20dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:text="男"
                android:textColor="#FF000000"
                android:textSize="20sp" />

            <Switch
                android:id="@+id/sw_sex"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:text="女"
                android:textColor="#FF000000"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_h"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="夫"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_w"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="妻"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_clr"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="10dp"
                android:text="C"
                android:textColor="#FF0080FF"
                android:textSize="35sp" />

            <ImageButton
                android:id="@+id/iv_del"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="10dp"
                android:src="@drawable/ic_delete" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_f"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="父"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_m"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="母"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_ob"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="兄"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_lb"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="弟"
                android:textColor="#FF000000"
                android:textSize="25sp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_os"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="姐"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_ls"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="妹"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_s"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="子"
                android:textColor="#FF000000"
                android:textSize="25sp" />

            <Button
                android:id="@+id/btn_d"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:padding="16dp"
                android:text="女"
                android:textColor="#FF000000"
                android:textSize="25sp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_each"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/radio_button_selector"
                android:enabled="false"
                android:padding="10dp"
                android:text="互查"
                android:textColor="#FFD6D6D6"
                android:textSize="20sp" />

            <Button
                android:id="@+id/btn_eq"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_weight="1"
                android:background="@drawable/shape_radio_button_unpressed"
                android:backgroundTint="#FF0080FF"
                android:padding="10dp"
                android:text="="
                android:textColor="#FFFFFFFF"
                android:textSize="35sp" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

2.获取亲戚关系表

RelationShipData.java :

public class RelationShipData {
	public String[][] getRelationShipDataByMan() {
		String[][] relationshipData = {
				{"我", "爸爸", "妈妈", "哥哥", "弟弟", "姐姐", "妹妹", "儿子", "女儿", "妻子", "丈夫", "未知亲戚"},
				{"爸爸", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "我", "妹妹", "妈妈", "", "未知亲戚"},
				{"妈妈", "外公", "外婆", "大舅", "小舅", "大姨", "小姨", "我", "妹妹", "", "爸爸", "未知亲戚"},
				{"哥哥", "爸爸", "妈妈", "哥哥", "我", "姐姐", "妹妹", "侄子", "侄女", "嫂子", "", "未知亲戚"},
				{"弟弟", "爸爸", "妈妈", "我", "弟弟", "姐姐", "妹妹", "侄子", "侄女", "弟妹", "", "未知亲戚"},
				{"姐姐", "爸爸", "妈妈", "哥哥", "我", "姐姐", "妹妹", "外甥", "外甥女", "", "姐夫", "未知亲戚"},
				{"妹妹", "爸爸", "妈妈", "我", "弟弟", "姐姐", "妹妹", "外甥", "外甥女", "", "妹夫", "未知亲戚"},
				{"儿子", "我", "妻子", "儿子", "儿子", "女儿", "女儿", "孙子", "孙女", "儿媳", "", "未知亲戚"},
				{"女儿", "我", "妻子", "儿子", "儿子", "女儿", "女儿", "外孙", "外孙女", "", "女婿", "未知亲戚"},
				{"妻子", "岳父", "岳母", "大舅子", "小舅子", "大姨子", "小姨子", "儿子", "女儿", "", "我", "未知亲戚"},
				{"丈夫", "", "", "", "", "", "", "", "", "", "", "未知亲戚"},
				{"爷爷", "曾祖父", "曾祖母", "伯祖父", "叔祖父", "祖姑母", "祖姑母", "爸爸", "姑妈", "奶奶", "", "未知亲戚"},
				{"奶奶", "曾外祖父", "曾外祖母", "舅公", "舅公", "祖姨母", "祖姨母", "爸爸", "姑妈", "", "爷爷", "未知亲戚"},
				{"伯父", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "堂哥", "堂姐", "伯母", "", "未知亲戚"},
				{"叔叔", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "堂弟", "堂妹", "婶婶", "", "未知亲戚"},
				{"姑妈", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "姑表哥", "姑表姐", "", "姑丈", "未知亲戚"},
				{"外公", "外曾祖父", "外曾祖母", "伯外祖父", "叔外祖父", "姑外祖母", "姑外祖母", "舅舅", "妈妈", "外婆", "", "未知亲戚"},
				{"外婆", "外曾外祖父", "外曾外祖母", "外舅公", "外舅公", "姨外祖母", "姨外祖母", "舅舅", "妈妈", "", "外公", "未知亲戚"},
				{"大舅", "外公", "外婆", "大舅", "舅舅", "大姨", "妈妈", "舅表哥", "舅表姐", "大舅妈", "", "未知亲戚"},
				{"小舅", "外公", "外婆", "舅舅", "小舅", "妈妈", "小姨", "舅表弟", "舅表妹", "小舅妈", "", "未知亲戚"},
				{"舅舅", "外公", "外婆", "大舅", "小舅", "大姨", "小姨", "舅表哥", "舅表姐", "舅妈", "", "未知亲戚"},
				{"大姨", "外公", "外婆", "大舅", "舅舅", "大姨", "妈妈", "姨表哥", "姨表姐", "", "大姨父", "未知亲戚"},
				{"小姨", "外公", "外婆", "舅舅", "小舅", "妈妈", "小姨", "姨表弟", "姨表妹", "", "小姨父", "未知亲戚"},
				{"侄子", "哥哥", "嫂子", "侄子", "侄子", "侄女", "侄女", "侄孙子", "侄孙女", "侄媳", "", "未知亲戚"},
				{"侄女", "哥哥", "嫂子", "侄子", "侄子", "侄女", "侄女", "外侄孙", "外侄孙女", "", "侄女婿", "未知亲戚"},
				{"嫂子", "姻伯父", "姻伯母", "姻兄", "姻弟", "姻姐", "姻妹", "侄子", "侄女", "", "哥哥", "未知亲戚"},
				{"弟妹", "姻叔父", "姻叔母", "姻兄", "姻弟", "姻姐", "姻妹", "侄子", "侄女", "", "弟弟", "未知亲戚"},
				{"外甥", "姐夫", "姐姐", "外甥", "外甥", "外甥女", "外甥女", "外甥孙", "外甥孙女", "外甥媳妇", "", "未知亲戚"},
				{"外甥女", "姐夫", "姐姐", "外甥", "外甥", "外甥女", "外甥女", "外甥孙", "外甥孙女", "", "外甥女婿", "未知亲戚"},
				{"姐夫", "姻世伯", "姻伯母", "姻兄", "姻弟", "姻姐", "姻妹", "外甥", "外甥女", "姐姐", "", "未知亲戚"},
				{"妹夫", "姻世伯", "姻伯母", "姻兄", "姻弟", "姻姐", "姻妹", "外甥", "外甥女", "妹妹", "", "未知亲戚"},
				{"孙子", "儿子", "儿媳", "孙子", "孙子", "孙女", "孙女", "曾孙", "曾孙女", "孙媳", "", "未知亲戚"},
				{"孙女", "儿子", "儿媳", "孙子", "孙子", "孙女", "孙女", "曾外孙", "曾外孙女", "", "孙女婿", "未知亲戚"},
				{"儿媳", "亲家公", "亲家母", "姻侄", "姻侄", "姻侄女", "姻侄女", "孙子", "孙女", "", "儿子", "未知亲戚"},
				{"外孙女", "女婿", "女儿", "外孙", "外孙", "外孙女", "外孙女", "外曾外孙", "外曾外孙女", "", "外孙女婿", "未知亲戚"},
				{"外孙", "女婿", "女儿", "外孙", "外孙", "外孙女", "外孙女", "外曾孙", "外曾孙女", "外孙媳", "", "未知亲戚"},
				{"女婿", "亲家公", "亲家母", "姻侄", "姻侄", "姻侄女", "姻侄女", "外孙", "外孙女", "女儿", "", "未知亲戚"},
				{"岳父", "太岳父", "太岳母", "伯岳", "叔岳", "姑岳母", "姑岳母", "大舅子", "大姨子", "岳母", "", "未知亲戚"},
				{"岳母", "外太岳父", "外太岳母", "舅岳父", "舅岳父", "姨岳母", "姨岳母", "大舅子", "大姨子", "", "岳父", "未知亲戚"},
				{"大舅子", "岳父", "岳母", "大舅子", "小舅子", "大姨子", "妻子", "内侄", "内侄女", "舅嫂", "", "未知亲戚"},
				{"小舅子", "岳父", "岳母", "大舅子", "小舅子", "妻子", "小姨子", "内侄", "内侄女", "舅弟媳", "", "未知亲戚"},
				{"大姨子", "岳父", "岳母", "大舅子", "小舅子", "大姨子", "妻子", "内甥", "姨甥女", "", "大姨夫", "未知亲戚"},
				{"小姨子", "岳父", "岳母", "大舅子", "小舅子", "妻子", "小姨子", "内甥", "姨甥女", "", "小姨夫", "未知亲戚"},
				{"曾祖父", "高祖父", "高祖母", "曾伯祖父", "曾叔祖父", "增祖姑母", "增祖姑母", "爷爷", "祖姑母", "曾祖母", "", "未知亲戚"},
				{"曾祖母", "高外祖父", "高外祖母", "舅曾祖父", "舅曾祖父", "姨曾祖母", "姨曾祖母", "爷爷", "祖姑母", "", "曾祖父", "未知亲戚"},
				{"伯祖父", "曾祖父", "曾祖母", "伯祖父", "爷爷", "祖姑母", "祖姑母", "堂伯", "堂姑", "伯祖母", "", "未知亲戚"},
				{"叔祖父", "曾祖父", "曾祖母", "爷爷", "叔祖父", "祖姑母", "祖姑母", "堂伯", "堂姑", "叔祖母", "", "未知亲戚"},
				{"祖姑母", "曾祖父", "曾祖母", "伯祖父", "爷爷", "祖姑母", "祖姑母", "姑表伯父", "姑表姑母", "", "祖姑父", "未知亲戚"},
				{"曾外祖父", "祖太爷", "祖太太", "伯曾外祖父", "叔曾外祖父", "姑曾外祖母", "姑曾外祖母", "舅公", "奶奶", "曾外祖母", "", "未知亲戚"},
				{"曾外祖母", "祖太姥爷", "祖太姥姥", "舅曾外祖父", "舅曾外祖父", "姨曾外祖母", "姨曾外祖母", "舅公", "奶奶", "", "曾外祖父", "未知亲戚"},
				{"舅公", "曾外祖父", "曾外祖母", "舅公", "舅公", "祖姨母", "奶奶", "舅表伯父", "舅表姑母", "舅婆", "", "未知亲戚"},
				{"祖姨母", "曾外祖父", "曾外祖母", "舅公", "舅公", "祖姨母", "奶奶", "姨表伯父", "姨表姑母", "", "祖姨夫", "未知亲戚"},
				{"堂哥", "伯父", "伯母", "堂哥", "堂弟", "堂姐", "堂妹", "堂侄", "堂侄女", "堂嫂", "", "未知亲戚"},
				{"堂弟", "叔叔", "婶婶", "堂哥", "堂弟", "堂姐", "堂妹", "堂侄", "堂侄女", "堂弟媳", "", "未知亲戚"},
				{"堂姐", "伯父", "伯母", "堂哥", "堂弟", "堂姐", "堂妹", "堂外甥", "堂外甥女", "", "堂姐夫", "未知亲戚"},
				{"堂妹", "叔叔", "婶婶", "堂哥", "堂弟", "堂姐", "堂妹", "堂外甥", "堂外甥女", "", "堂妹夫", "未知亲戚"},
				{"伯母", "姻伯公", "姻伯婆", "姻世伯", "姻世伯", "姻伯母", "姻伯母", "堂哥", "堂姐", "", "伯父", "未知亲戚"},
				{"婶婶", "姻伯公", "姻伯婆", "姻世伯", "姻世伯", "姻伯母", "姻伯母", "堂弟", "堂妹", "", "叔叔", "未知亲戚"},
				
				{"姑表哥", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑表姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑丈", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"外曾祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"外曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"外舅公", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"舅表哥", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"大舅妈", "", "", "", "", "", "", "", "", "", "", ""},
				{"小舅妈", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅妈", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表弟", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表妹", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"姨表哥", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表弟", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表妹", "", "", "", "", "", "", "", "", "", "", ""},
				{"大姨父", "", "", "", "", "", "", "", "", "", "", ""},
				{"小姨父", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"侄孙子", "", "", "", "", "", "", "", "", "", "", ""},
				{"外侄孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外侄孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄女婿", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"姻伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻叔父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻伯母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻叔母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻兄", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻弟", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻妹", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"外甥孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥媳妇", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥女婿", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻世伯", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"曾孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾外孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾外孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"孙媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"孙女婿", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"亲家公", "", "", "", "", "", "", "", "", "", "", ""},
				{"亲家母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻侄", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻侄女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾外孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾外孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外孙女婿", "", "", "", "", "", "", "", "", "", "", ""},
				{"外孙媳", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"太岳父", "", "", "", "", "", "", "", "", "", "", ""},
				{"外太岳父", "", "", "", "", "", "", "", "", "", "", ""},
				{"太岳母", "", "", "", "", "", "", "", "", "", "", ""},
				{"外太岳母", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯岳", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔岳", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅岳父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑岳母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨岳母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"内侄", "", "", "", "", "", "", "", "", "", "", ""},
				{"内侄女", "", "", "", "", "", "", "", "", "", "", ""},
				{"内甥", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨甥女", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅嫂", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅弟媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"大姨夫", "", "", "", "", "", "", "", "", "", "", ""},
				{"小姨夫", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"高祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"高祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"高外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"高外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾伯祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾叔祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅曾祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"增祖姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨曾祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"堂伯", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂姑", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑表伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑表姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖姑父", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"祖太爷", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖太太", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖太姥爷", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖太姥姥", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑曾外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨曾外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"舅表伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅婆", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖姨夫", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"堂侄", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂侄女", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂嫂", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂弟媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂外甥", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂外甥女", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂姐夫", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂妹夫", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"姻伯公", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻伯婆", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚"}
		};
		return relationshipData;
	}
	
	public String[][] getRelationShipDataByWoman() {
		String[][] relationshipData = {
				{"我", "爸爸", "妈妈", "哥哥", "弟弟", "姐姐", "妹妹", "儿子", "女儿", "妻子", "丈夫", "未知亲戚"},
				{"爸爸", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "弟弟", "我", "妈妈", "", "未知亲戚"},
				{"妈妈", "外公", "外婆", "大舅", "小舅", "大姨", "小姨", "弟弟", "我", "", "爸爸", "未知亲戚"},
				{"哥哥", "爸爸", "妈妈", "哥哥", "弟弟", "姐姐", "我", "侄子", "侄女", "嫂子", "", "未知亲戚"},
				{"弟弟", "爸爸", "妈妈", "哥哥", "弟弟", "我", "妹妹", "侄子", "侄女", "弟妹", "", "未知亲戚"},
				{"姐姐", "爸爸", "妈妈", "哥哥", "弟弟", "姐姐", "我", "外甥", "外甥女", "", "姐夫", "未知亲戚"},
				{"妹妹", "爸爸", "妈妈", "哥哥", "弟弟", "我", "妹妹", "外甥", "外甥女", "", "妹夫", "未知亲戚"},
				{"儿子", "丈夫", "我", "儿子", "儿子", "女儿", "女儿", "孙子", "孙女", "儿媳", "", "未知亲戚"},
				{"女儿", "丈夫", "我", "儿子", "儿子", "女儿", "女儿", "外孙", "外孙女", "", "女婿", "未知亲戚"},
				{"妻子", "", "", "", "", "", "", "", "", "", "", "未知亲戚"},
				{"丈夫", "公公", "婆婆", "大伯子", "小叔子", "大姑子", "小姑子", "儿子", "女儿", "我", "", "未知亲戚"},
				{"爷爷", "曾祖父", "曾祖母", "伯祖父", "叔祖父", "祖姑母", "祖姑母", "爸爸", "姑妈", "奶奶", "", "未知亲戚"},
				{"奶奶", "曾外祖父", "曾外祖母", "舅公", "舅公", "祖姨母", "祖姨母", "爸爸", "姑妈", "", "爷爷", "未知亲戚"},
				{"伯父", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "堂哥", "堂姐", "伯母", "", "未知亲戚"},
				{"叔叔", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "堂弟", "堂妹", "婶婶", "", "未知亲戚"},
				{"姑妈", "爷爷", "奶奶", "伯父", "叔叔", "姑妈", "姑妈", "姑表哥", "姑表姐", "", "姑丈", "未知亲戚"},
				{"外公", "外曾祖父", "外曾祖母", "伯外祖父", "叔外祖父", "姑外祖母", "姑外祖母", "舅舅", "妈妈", "外婆", "", "未知亲戚"},
				{"外婆", "外曾外祖父", "外曾外祖母", "外舅公", "外舅公", "姨外祖母", "姨外祖母", "舅舅", "妈妈", "", "外公", "未知亲戚"},
				{"大舅", "外公", "外婆", "大舅", "舅舅", "大姨", "妈妈", "舅表哥", "舅表姐", "大舅妈", "", "未知亲戚"},
				{"小舅", "外公", "外婆", "舅舅", "小舅", "妈妈", "小姨", "舅表弟", "舅表妹", "小舅妈", "", "未知亲戚"},
				{"舅舅", "外公", "外婆", "大舅", "小舅", "大姨", "小姨", "舅表哥", "舅表姐", "舅妈", "", "未知亲戚"},
				{"大姨", "外公", "外婆", "大舅", "舅舅", "大姨", "妈妈", "姨表哥", "姨表姐", "", "大姨父", "未知亲戚"},
				{"小姨", "外公", "外婆", "舅舅", "小舅", "妈妈", "小姨", "姨表弟", "姨表妹", "", "小姨父", "未知亲戚"},
				{"侄子", "哥哥", "嫂子", "侄子", "侄子", "侄女", "侄女", "侄孙子", "侄孙女", "侄媳", "", "未知亲戚"},
				{"侄女", "哥哥", "嫂子", "侄子", "侄子", "侄女", "侄女", "外侄孙", "外侄孙女", "", "侄女婿", "未知亲戚"},
				{"嫂子", "姻伯父", "姻伯母", "姻兄", "姻弟", "姻姐", "姻妹", "侄子", "侄女", "", "哥哥", "未知亲戚"},
				{"弟妹", "姻叔父", "姻叔母", "姻兄", "姻弟", "姻姐", "姻妹", "侄子", "侄女", "", "弟弟", "未知亲戚"},
				{"外甥", "姐夫", "姐姐", "外甥", "外甥", "外甥女", "外甥女", "外甥孙", "外甥孙女", "外甥媳妇", "", "未知亲戚"},
				{"外甥女", "姐夫", "姐姐", "外甥", "外甥", "外甥女", "外甥女", "外甥孙", "外甥孙女", "", "外甥女婿", "未知亲戚"},
				{"姐夫", "姻世伯", "姻伯母", "姻兄", "姻弟", "姻姐", "姻妹", "外甥", "外甥女", "姐姐", "", "未知亲戚"},
				{"妹夫", "姻世伯", "姻伯母", "姻兄", "姻弟", "姻姐", "姻妹", "外甥", "外甥女", "妹妹", "", "未知亲戚"},
				{"孙子", "儿子", "儿媳", "孙子", "孙子", "孙女", "孙女", "曾孙", "曾孙女", "孙媳", "", "未知亲戚"},
				{"孙女", "儿子", "儿媳", "孙子", "孙子", "孙女", "孙女", "曾外孙", "曾外孙女", "", "孙女婿", "未知亲戚"},
				{"儿媳", "亲家公", "亲家母", "姻侄", "姻侄", "姻侄女", "姻侄女", "孙子", "孙女", "", "儿子", "未知亲戚"},
				{"外孙女", "女婿", "女儿", "外孙", "外孙", "外孙女", "外孙女", "外曾外孙", "外曾外孙女", "", "外孙女婿", "未知亲戚"},
				{"外孙", "女婿", "女儿", "外孙", "外孙", "外孙女", "外孙女", "外曾孙", "外曾孙女", "外孙媳", "", "未知亲戚"},
				{"女婿", "亲家公", "亲家母", "姻侄", "姻侄", "姻侄女", "姻侄女", "外孙", "外孙女", "女儿", "", "未知亲戚"},
				{"公公", "祖翁", "祖婆", "伯翁", "叔公", "姑婆", "姑婆", "大伯子", "大姑子", "婆婆", "", "未知亲戚"},
				{"婆婆", "外公", "外婆", "舅公", "舅公", "姨婆", "姨婆", "大伯子", "大姑子", "", "公公", "未知亲戚"},
				{"大伯子", "公公", "婆婆", "大伯子", "丈夫", "大姑子", "小姑子", "婆家侄", "侄女", "大婶子", "", "未知亲戚"},
				{"小叔子", "公公", "婆婆", "丈夫", "小叔子", "大姑子", "小姑子", "婆家侄", "侄女", "小婶子", "", "未知亲戚"},
				{"大姑子", "公公", "婆婆", "大伯子", "丈夫", "大姑子", "小姑子", "婆家甥", "外甥女", "", "大姑夫", "未知亲戚"},
				{"小姑子", "公公", "婆婆", "丈夫", "小叔子", "大姑子", "小姑子", "婆家甥", "外甥女", "", "小姑夫", "未知亲戚"},
				{"曾祖父", "高祖父", "高祖母", "曾伯祖父", "曾叔祖父", "增祖姑母", "增祖姑母", "爷爷", "祖姑母", "曾祖母", "", "未知亲戚"},
				{"曾祖母", "高外祖父", "高外祖母", "舅曾祖父", "舅曾祖父", "姨曾祖母", "姨曾祖母", "爷爷", "祖姑母", "", "曾祖父", "未知亲戚"},
				{"伯祖父", "曾祖父", "曾祖母", "伯祖父", "爷爷", "祖姑母", "祖姑母", "堂伯", "堂姑", "伯祖母", "", "未知亲戚"},
				{"叔祖父", "曾祖父", "曾祖母", "爷爷", "叔祖父", "祖姑母", "祖姑母", "堂伯", "堂姑", "叔祖母", "", "未知亲戚"},
				{"祖姑母", "曾祖父", "曾祖母", "伯祖父", "爷爷", "祖姑母", "祖姑母", "姑表伯父", "姑表姑母", "", "祖姑父", "未知亲戚"},
				{"曾外祖父", "祖太爷", "祖太太", "伯曾外祖父", "叔曾外祖父", "姑曾外祖母", "姑曾外祖母", "舅公", "奶奶", "曾外祖母", "", "未知亲戚"},
				{"曾外祖母", "祖太姥爷", "祖太姥姥", "舅曾外祖父", "舅曾外祖父", "姨曾外祖母", "姨曾外祖母", "舅公", "奶奶", "", "曾外祖父", "未知亲戚"},
				{"舅公", "曾外祖父", "曾外祖母", "舅公", "舅公", "祖姨母", "奶奶", "舅表伯父", "舅表姑母", "舅婆", "", "未知亲戚"},
				{"祖姨母", "曾外祖父", "曾外祖母", "舅公", "舅公", "祖姨母", "奶奶", "姨表伯父", "姨表姑母", "", "祖姨夫", "未知亲戚"},
				{"堂哥", "伯父", "伯母", "堂哥", "堂弟", "堂姐", "堂妹", "堂侄", "堂侄女", "堂嫂", "", "未知亲戚"},
				{"堂弟", "叔叔", "婶婶", "堂哥", "堂弟", "堂姐", "堂妹", "堂侄", "堂侄女", "堂弟媳", "", "未知亲戚"},
				{"堂姐", "伯父", "伯母", "堂哥", "堂弟", "堂姐", "堂妹", "堂外甥", "堂外甥女", "", "堂姐夫", "未知亲戚"},
				{"堂妹", "叔叔", "婶婶", "堂哥", "堂弟", "堂姐", "堂妹", "堂外甥", "堂外甥女", "", "堂妹夫", "未知亲戚"},
				{"伯母", "姻伯公", "姻伯婆", "姻世伯", "姻世伯", "姻伯母", "姻伯母", "堂哥", "堂姐", "", "伯父", "未知亲戚"},
				{"婶婶", "姻伯公", "姻伯婆", "姻世伯", "姻世伯", "姻伯母", "姻伯母", "堂弟", "堂妹", "", "叔叔", "未知亲戚"},
				
				{"姑表哥", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑表姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑丈", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"外曾祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"外曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"外舅公", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"舅表哥", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"大舅妈", "", "", "", "", "", "", "", "", "", "", ""},
				{"小舅妈", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅妈", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表弟", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表妹", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"姨表哥", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表弟", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表妹", "", "", "", "", "", "", "", "", "", "", ""},
				{"大姨父", "", "", "", "", "", "", "", "", "", "", ""},
				{"小姨父", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"侄孙子", "", "", "", "", "", "", "", "", "", "", ""},
				{"外侄孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外侄孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄女婿", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"姻伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻叔父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻伯母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻叔母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻兄", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻弟", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻姐", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻妹", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"外甥孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥媳妇", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥女婿", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻世伯", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"曾孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾外孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾外孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"孙媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"孙女婿", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"亲家公", "", "", "", "", "", "", "", "", "", "", ""},
				{"亲家母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻侄", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻侄女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾外孙", "", "", "", "", "", "", "", "", "", "", ""},
				{"外曾外孙女", "", "", "", "", "", "", "", "", "", "", ""},
				{"外孙女婿", "", "", "", "", "", "", "", "", "", "", ""},
				{"外孙媳", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"祖翁", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖婆", "", "", "", "", "", "", "", "", "", "", ""},
				{"外婆", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯翁", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔公", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅公", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑婆", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨婆", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"婆家侄", "", "", "", "", "", "", "", "", "", "", ""},
				{"侄女", "", "", "", "", "", "", "", "", "", "", ""},
				{"婆家甥", "", "", "", "", "", "", "", "", "", "", ""},
				{"外甥女", "", "", "", "", "", "", "", "", "", "", ""},
				{"大婶子", "", "", "", "", "", "", "", "", "", "", ""},
				{"小婶子", "", "", "", "", "", "", "", "", "", "", ""},
				{"大姑夫", "", "", "", "", "", "", "", "", "", "", ""},
				{"小姑夫", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"高祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"高祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"高外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"高外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾伯祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"曾叔祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅曾祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"增祖姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨曾祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"堂伯", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂姑", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑表伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑表姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖姑父", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"祖太爷", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖太太", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖太姥爷", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖太姥姥", "", "", "", "", "", "", "", "", "", "", ""},
				{"伯曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"叔曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅曾外祖父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姑曾外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨曾外祖母", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"舅表伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表伯父", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅表姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"姨表姑母", "", "", "", "", "", "", "", "", "", "", ""},
				{"舅婆", "", "", "", "", "", "", "", "", "", "", ""},
				{"祖姨夫", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"堂侄", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂侄女", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂嫂", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂弟媳", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂外甥", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂外甥女", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂姐夫", "", "", "", "", "", "", "", "", "", "", ""},
				{"堂妹夫", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"姻伯公", "", "", "", "", "", "", "", "", "", "", ""},
				{"姻伯婆", "", "", "", "", "", "", "", "", "", "", ""},
				
				{"未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚", "未知亲戚"}
		};
		return relationshipData;
	}
}

3.主代码

RelativesCallCalculatorActivity.java :

public class RelativesCallCalculatorActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
	
	private List<Button> buttonList = new ArrayList<>();
	ImageButton iv_del;
	Switch sw_sex;
	TextView tv_input;
	TextView tv_results;
	
	// 初始值的性别
	private boolean init_sex;
	// 当前结果的性别
	private boolean sex;
	// 操作数数组
	private List<String> callList = new ArrayList<>();
	// 显示的文本内容
	private String showText = "";
	// 当前运算结果
	private String resultsText = "";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_relatives_call_calculator);
		
		// 获取控件,并添加点击事件
		findViewById(R.id.iv_back).setOnClickListener(this);
		
		buttonList.add(findViewById(R.id.btn_h));
		buttonList.add(findViewById(R.id.btn_w));
		buttonList.add(findViewById(R.id.btn_f));
		buttonList.add(findViewById(R.id.btn_m));
		buttonList.add(findViewById(R.id.btn_ob));
		buttonList.add(findViewById(R.id.btn_lb));
		buttonList.add(findViewById(R.id.btn_os));
		buttonList.add(findViewById(R.id.btn_ls));
		buttonList.add(findViewById(R.id.btn_s));
		buttonList.add(findViewById(R.id.btn_d));
		buttonList.add(findViewById(R.id.btn_each));
		buttonList.add(findViewById(R.id.btn_eq));
		buttonList.add(findViewById(R.id.btn_clr));
		iv_del = findViewById(R.id.iv_del);
		sw_sex = findViewById(R.id.sw_sex);
		tv_input = findViewById(R.id.tv_input);
		tv_results = findViewById(R.id.tv_results);
		
		callList.add("我");
		init_sex = sex = sw_sex.isChecked();
		sw_sex.setOnCheckedChangeListener(this);
		// 给按钮设置的点击事件
		for (Button button : buttonList) {
			button.setOnClickListener(this);
		}
		iv_del.setOnClickListener(this);
		forbiddenButton();
	}
	
	@Override
	public void onClick(View v) {
		if (v.getId() != R.id.iv_back && v.getId() != R.id.btn_clr
				&& v.getId() != R.id.iv_del && v.getId() != R.id.btn_eq
				&& resultsText.equals("关系有点远,年长就叫老祖宗~\n同龄人就叫帅哥美女吧"))
			return;
		switch (v.getId()) {
			// 点击了返回按钮
			case R.id.iv_back:
				finish();
				break;
			
			// 点击了清除按钮
			case R.id.btn_clr:
				emphasisShowInput();
				init_sex = sex = sw_sex.isChecked();
				forbiddenButton();
				clear();
				break;
			
			// 点击了删除按钮
			case R.id.iv_del:
				emphasisShowInput();
				delete();
				if (callList.size() > 1) {
					if (isMan(callList.get(callList.size() - 1)))
						sex = false;
					else
						sex = true;
				} else {
					sex = sw_sex.isChecked();
				}
				forbiddenButton();
				break;
			
			// 点击了等于按钮
			case R.id.btn_eq:
				if (callList.size() <= 1)
					break;
				emphasisShowResults();
				if (!showText.equals("TA称呼我") && !resultsText.equals("关系有点远,年长就叫老祖宗~\n同龄人就叫帅哥美女吧")) {
					buttonList.get(10).setEnabled(true);
					buttonList.get(10).setTextColor(Color.parseColor("#FF000000"));
					refreshText();
				}
				break;
			
			// 点击了互查按钮
			case R.id.btn_each:
				if (!showText.equals("TA称呼我")) {
					emphasisShowResults();
					peerReview();
				} else {
					emphasisShowInput();
					refreshText();
					buttonList.get(10).setEnabled(false);
					buttonList.get(10).setTextColor(Color.parseColor("#FFD6D6D6"));
				}
				break;
			
			// 点击了亲戚关系按钮
			case R.id.btn_h:
				emphasisShowInput();
				callList.add("丈夫");
				sex = false;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_w:
				emphasisShowInput();
				callList.add("妻子");
				sex = true;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_f:
				emphasisShowInput();
				callList.add("爸爸");
				sex = false;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_m:
				emphasisShowInput();
				callList.add("妈妈");
				sex = true;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_ob:
				emphasisShowInput();
				callList.add("哥哥");
				sex = false;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_lb:
				emphasisShowInput();
				callList.add("弟弟");
				sex = false;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_os:
				emphasisShowInput();
				callList.add("姐姐");
				sex = true;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_ls:
				emphasisShowInput();
				callList.add("妹妹");
				sex = true;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_s:
				emphasisShowInput();
				callList.add("儿子");
				sex = false;
				forbiddenButton();
				refreshText();
				break;
			
			case R.id.btn_d:
				emphasisShowInput();
				callList.add("女儿");
				sex = true;
				forbiddenButton();
				refreshText();
				break;
		}
	}
	
	// 清空并初始化
	private void clear() {
		callList.clear();
		callList.add("我");
		resultsText = "";
		refreshText();
	}
	
	// 刷新文本显示
	private void refreshText() {
		showText = "";
		resultsText = "";
		
		for (int i = 0; i < callList.size(); i++) {
			showText += callList.get(i);
			if (i == callList.size() - 1)
				break;
			showText += "的";
		}
		if (callList.size() > 8)
			resultsText = "关系有点远,年长就叫老祖宗~\n同龄人就叫帅哥美女吧";
		else if (callList.size() > 1)
			operation(callList, init_sex);
		
		tv_input.setText(showText);
		tv_results.setText(resultsText);
	}
	
	// 回退
	private void delete() {
		if (callList.size() > 1) {
			callList.remove(callList.size() - 1);
			operation(callList, init_sex);
			refreshText();
		}
	}
	
	// 运算
	private void operation(List<String> list, boolean b) {
		String[][] relationshipData;
		if (b)
			relationshipData = new RelationShipData().getRelationShipDataByWoman();
		else
			relationshipData = new RelationShipData().getRelationShipDataByMan();
		int column = 0, row = 0;
		String resultValue = list.get(0);
		for (int i = 1; i < list.size(); i++) {
			for (int m = 0; m < relationshipData.length; ++m) {
				if (relationshipData[m][0].equals(resultValue)) {
					row = m;
					break;
				}
			}
			for (int n = 0; n < relationshipData[0].length; n++) {
				if (relationshipData[0][n].equals(list.get(i))) {
					column = n;
					break;
				}
			}
			resultValue = relationshipData[row][column];
			if (!isExist(resultValue, relationshipData)) {
				resultValue = "未知亲戚";
				break;
			}
		}
		if (resultValue.equals("未知亲戚") || resultValue.equals(""))
			resultsText = "关系有点远,年长就叫老祖宗~\n同龄人就叫帅哥美女吧";
		else
			resultsText = resultValue;
	}
	
	// 判断某个值在二维数组中的行首值中是否存在
	public boolean isExist(String value, String[][] array) {
		for (int i = 0; i < array.length; i++) {
			if (value.equals(array[i][0])) {
				return true;
			}
		}
		return false;
	}
	
	// 互查
	private void peerReview() {
		showText = "TA称呼我";
		List<String> tempList = new ArrayList<>();
		boolean tempSex;
		tempList.add("我");
		for (int i = callList.size() - 1; i > 0; i--) {
			if ((callList.get(i - 1).equals("我") && !init_sex) || isMan(callList.get(i - 1))) {
				if (callList.get(i).equals("儿子") || callList.get(i).equals("女儿"))
					tempList.add("爸爸");
				else if (callList.get(i).equals("弟弟") || callList.get(i).equals("妹妹"))
					tempList.add("哥哥");
				else if (callList.get(i).equals("哥哥") || callList.get(i).equals("姐姐"))
					tempList.add("弟弟");
				else if (callList.get(i).equals("爸爸") || callList.get(i).equals("妈妈"))
					tempList.add("儿子");
				else if (callList.get(i).equals("妻子"))
					tempList.add("丈夫");
			} else {
				if (callList.get(i).equals("儿子") || callList.get(i).equals("女儿"))
					tempList.add("妈妈");
				else if (callList.get(i).equals("弟弟") || callList.get(i).equals("妹妹"))
					tempList.add("姐姐");
				else if (callList.get(i).equals("哥哥") || callList.get(i).equals("姐姐"))
					tempList.add("妹妹");
				else if (callList.get(i).equals("爸爸") || callList.get(i).equals("妈妈"))
					tempList.add("女儿");
				else if (callList.get(i).equals("丈夫"))
					tempList.add("妻子");
			}
		}
		// 判断“我”的性别
		if (isMan(callList.get(callList.size() - 1)))
			tempSex = false;
		else
			tempSex = true;
		operation(tempList, tempSex);
		tv_input.setText(showText);
		tv_results.setText(resultsText);
	}
	
	// 判断该亲戚是否为男性
	private boolean isMan(String s) {
		if (s.equals("丈夫") || s.equals("爸爸") || s.equals("哥哥")
				|| s.equals("弟弟") || s.equals("儿子"))
			return true;
		else
			return false;
	}
	
	// 重点显示输入
	private void emphasisShowInput() {
		tv_input.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
		tv_input.setTextColor(Color.parseColor("#FF000000"));
		tv_results.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
		tv_results.setTextColor(Color.parseColor("#FF959595"));
		buttonList.get(10).setEnabled(false);
		buttonList.get(10).setTextColor(Color.parseColor("#FFD6D6D6"));
	}
	
	// 重点显示结果
	private void emphasisShowResults() {
		tv_results.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
		tv_results.setTextColor(Color.parseColor("#FF000000"));
		tv_input.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
		tv_input.setTextColor(Color.parseColor("#FF959595"));
	}
	
	// 禁用夫 \ 妻按钮
	private void forbiddenButton() {
		if (sex) {
			buttonList.get(1).setTextColor(Color.parseColor("#FFD6D6D6"));
			buttonList.get(1).setEnabled(false);
			buttonList.get(0).setTextColor(Color.parseColor("#FF000000"));
			buttonList.get(0).setEnabled(true);
		} else {
			buttonList.get(0).setTextColor(Color.parseColor("#FFD6D6D6"));
			buttonList.get(0).setEnabled(false);
			buttonList.get(1).setTextColor(Color.parseColor("#FF000000"));
			buttonList.get(1).setEnabled(true);
		}
	}
	
	@Override
	public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
		init_sex = sex = b;
		clear();
		forbiddenButton();
		emphasisShowInput();
	}
}

总结

以上就是亲戚称呼计算器的开发与实现的内容。

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

此名哥已占

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值