Published Date : 2021年2月28日8:26

パート 7: 給与所得者の所得税と住民税を計算するAndroidアプリ
Part 7: Android App Calculates Income and Resident Taxes for Salaried Workers


This blog has an English translation


ニコニコ動画にアップした動画のまとめ記事です。

This is a summary blog post about a video I uploaded to NicoNico.

細かい部分は動画を参考にしてください。

Please refer to the video for details.


目次

Table of Contents




① 動画の説明
① Video Description



警告:

今回説明する給与所得者の所得税及び住民税を計算するツールは、あくまで簡易的なお遊び用のツールです。

正確な数値、計算方法は各自で調べて下さい。

このツールは大雑把に大体の見積りを計算して楽しむ為のツールです。

決して従業員の年末調整や個人の確定申告等に使用しないでください。

さらに、税金の計算方法は変更される場合があり、控除についても同様です。

また、控除や税金の計算方法が間違っている可能性もありますので、

あまり信用せずに、各自で調べてから実験してみてください。

このツールを使って何かしらの損害が発生したとしても、私は一切の責任を負いません。

Warning:

​The tool I'm going to show you for calculating income and residence taxes for salaried workers is just a simple tool for playing.

​Please check the exact number and calculation method by yourself.

​This tool is used to calculate rough estimates and enjoy them.

​Do not use for year-end adjustment of employees or for individual tax return.

In addition, the method of calculating taxes and deductions may change.

Also, there is a possibility that the deduction and tax calculation methods are incorrect.

Don't trust it too much, and test it yourself.

​I will not be liable for any damage caused by using this tool.

前回の続きです。

Continued from last time.


Responsive image

[MainActivity.java]へ戻ります。

Return to [MainActivity.java].

税金計算をするアクティビティへ移動するボタンのメソッドを書きます。

Write the method for the button to go to the activity for tax calculation.

いつも通りにアクティビティを指定してインテントのインスタンスを作成します。

Create an instance of the intent, specifying the activity as usual.

Intent intent = new Intent(this, CalcTaxesActivity.class);

では[app]で右クリックをして、画面の指示通りに空のアクティビティを作成してください。

Right-click in [app] and create the empty activity as instructed on the screen.

[MainActivity.java]へ戻り、[社会保険料の計算の結果を使うボタン]が押されたかどうかのブーリアン変数を用意します。

Return to [MainActivity.java] and creates a boolean variable to indicate whether [button that uses the results of the social insurance calculation] was pressed.

boolean useIs = false;

レイアウトIDを使って、[社会保険料の計算の結果を使うボタン]が押された時の処理を記述します。

The layout ID is used to describe what happens when [button that uses the results of the social insurance calculation] is clicked.

putExtraメソッドを使って社会保険料の総額の値をインテントのインスタンスにname引数で指定した名前で埋め込みます。

The putExtra method is used to populate the instance of the intent with the value of the total social insurance premium with the name specified by the name argument.

if (view.getId() == R.id.useIsResultBtn) {
    useIs = true;
    intent.putExtra("totalSocialInsurancePremium", totalSocialInsurancePremium);
}

ボタンが押されたか否かのブーリアン変数も入力します。

Also embded a boolean variable to indicate whether the button was clicked or not.

intent.putExtra("useIs", useIs);

そして、startActivityを使って起動させるアクティビティへintentのインスタンスを送ります。

It then sends an instance of intent to the activity that you want to invoke using startActivity.

startActivity(intent);

作成した税金計算用のアクティビティのJavaファイルへ移動します。

Navigate to the Java file for the activity you created for tax calculation.

社会保険料用の変数を宣言します。

Declare variables for social insurance premiums.

インテントのインスタンスを作成します。

Creates an instance of the intent.

インテントのインスタンスから値を取り出す準備をします。

Prepares to retrieve a value from an instance of the intent.

値を取り出していきます。

Retrieve values.

取り出した社会保険料を画面に表示させるメソッドを用意します。

Prepare a method to display the retrieved social insurance premium on the screen.

では税金計算用のアクティビティのレイアウトを作成していきましょう。

Now let's create an activity layout for tax calculation.

ScrollViewを配置します。

Position ScrollView.

その中にLinearLayoutを配置します。

Place a LinearLayout inside it.

その中に電卓アクティビティを起動させる為のボタンを配置します。

Position a button to launch calculator activity inside it.

イベントリスナーに登録したメソッドの中身を記述していきます。

Write the contents of the methods you registered with the event listener.

内容はメインアクティビティの時と変わりません。

The content is the same as in the main activity.

税金計算用のアクティビティへ戻り、テキストビューを配置します。

Return to the activity for tax calculation and place the text view.

その下にグリッドレイアウトを5行2列にして配置します。

Place the grid layout in five rows and two columns below it.

その中にテキストビューを配置します。

Place a text view inside it.

いつも通り[strings.xml]にレイアウト画面に表示させるテキストを記述していきましょう。

Write the text displayed on the layout screen in [strings.xml] as usual.

税金計算用のレイアウトファイルへ戻ります。

Return to the layout file for tax calculation.

給与収入を入力する用のエディットテキストを配置します。

Arranges edit text for entering salary revenue.

gravityをendにして数字を右端に寄せて表示させます。

Set gravity to end to display the numbers to the right.

imeOptionsをactionDoneにして入力フォーカスを自動で移動させないようにします。

Set imeOptions to actionDone to avoid moving the input focus automatically.

みなし給与収入の行です。

A row for deemed salary income.

給与所得控除の行です。

It is a row of employment income deduction.

給与所得の行です。

A row for employment income.

給与所得控除後の課税所得(総所得)の行です。

A row for Taxable Income after employment income deduction (gross income).

GridLayoutの下にテキストビューを配置します。

Place the text view below the GridLayout.

いつも通り[strings.xml]にレイアウト画面に表示させるテキストを記述していきましょう。

Write the text displayed on the layout screen in [strings.xml] as usual.

税金計算用のレイアウトファイルへ戻ります。

Return to the layout file for tax calculation.

グリッドレイアウトを3行2列にして配置します。

Place the grid layout in three rows and two columns.

社会保険料を入力させるエディットテキストとそのタイトルのテキストビューを配置する。

An edit text for inputting social insurance premiums and a text view of the title are arranged.

所得税用の社会保険料控除額の行。見やすいようにテキストの色を変えます。

A row of Social Insurance Premium Deduction for Income Tax. Change the text color to make it easier to see.

住民税用の社会保険料控除額の行。見やすいようにテキストの色を変えます。

A row of Social Insurance Premium Deduction for Resident Tax. Change the text color to make it easier to see.

ここまで作成したアプリの挙動を確かめてみましょう。

Let's take a look at the behavior of the apps we've created so far.


Responsive image

パート8へ続く。

Continue to Part 8.



以上です。お疲れ様です。

That's all. Thank you for your hard work.