阿摩線上測驗 登入

申論題資訊

試卷:106年 - 106 合作金庫商業銀行新進人員甄試試題_開放系統第一類程式設計人員:程式設計(以 APP、HTML5/CSS 與 RWD、JAVA、SQL 語言為主)、系統分析、 資料結構及資料庫應用#106965
科目:程式設計(以 JAVA、SQL 語言為主)、系統分析、資料結構及資料庫應用
年份:106年
排序:0

申論題內容

第一題: 請設計一個 APP,於程式啟動時,彈出對話框(Android 使用 AlertDialog、iOS 使用 UIAlertController),對話框標題顯示「行動銀行」,對話框訊息內容顯示「提醒您可安裝防毒 軟體,以提升行動交易安全!」,並於對話框內由左至右加入三顆按鈕,說明如下表:
6232eca169ba1.jpg (請擇一選擇以 Android 或 iOS 作答,Android 使用 JAVA 語言,iOS 使用 Objective-C 語言。如有非程式碼之相關屬性設定,請詳細敘述。)【20 分】

詳解 (共 1 筆)

詳解 提供者:hchungw
java
複製程式碼
package com.example.myapp;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
    private static final String PREF_DO_NOT_SHOW_AGAIN = "do_not_show_again";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 檢查用戶是否選擇 "不再提醒"
        boolean doNotShowAgain = PreferenceManager.getDefaultSharedPreferences(this)
                .getBoolean(PREF_DO_NOT_SHOW_AGAIN, false);
        if (!doNotShowAgain) {
            showAlertDialog();
        }
    }
    private void showAlertDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("行動銀行")
                .setMessage("提醒您可安裝防毒軟體,以提升行動交易安全!")
                .setPositiveButton("下次提醒我", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 下次啟動時會再顯示對話框
                        dialog.dismiss();
                    }
                })
                .setNeutralButton("了解更多", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 打開網頁
                        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.tabf.org.tw"));
                        startActivity(browserIntent);
                    }
                })
                .setNegativeButton("不再提醒", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 設置 "不再提醒" 選項
                        PreferenceManager.getDefaultSharedPreferences(MainActivity.this)
                                .edit()
                                .putBoolean(PREF_DO_NOT_SHOW_AGAIN, true)
                                .apply();
                        dialog.dismiss();
                    }
                });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}