Как восстановить изображение кнопки после срабатывания onConfigurationChanged - PullRequest
0 голосов
/ 29 марта 2020

Изображение кнопки было сброшено после того, как я наклонил свой планшет, и мне нужно восстановить его. Сложность состоит в том, что нет изображения по умолчанию для восстановления в «Button LP_image_hs_out = (Button) findViewById (LP_image_hs)», так как оно зависит от

  1. параметра, который был отправлен после «submit_ML * 1011». * "были нажаты, что вызвало" TOP_10YLuckPillar "
  2. внутри модуля" TOP_10YLuckPillar ", есть условие IF, чтобы решить, какое изображение показать в справке" Button LP_image_hs_out "

pls , спасибо

// MLC button click Start

public void submit_MLC(View v) {
    switch (v.getId()) {
        case R.id.LP_age_1:
            TOP_10YLuckPillar(LP_cnt_hs_hidden1, LP_cnt_eb_1, 0);
            break;
        case R.id.LP_age_2:
             TOP_10YLuckPillar(LP_cnt_hs_hidden2, LP_cnt_eb_2, different);
            break;
        case R.id.LP_age_3:
             TOP_10YLuckPillar(LP_cnt_hs_hidden3, LP_cnt_eb_3, different + 10);
            break;
        case R.id.LP_age_4:
            TOP_10YLuckPillar(LP_cnt_hs_hidden4, LP_cnt_eb_4, different + 20);
            break;
        case R.id.LP_age_5:
            TOP_10YLuckPillar(LP_cnt_hs_hidden5, LP_cnt_eb_5, different + 30);
            break;
        case R.id.LP_age_6:
            TOP_10YLuckPillar(LP_cnt_hs_hidden6, LP_cnt_eb_6, different + 40);
            break;
        case R.id.LP_age_7:
            TOP_10YLuckPillar(LP_cnt_hs_hidden7, LP_cnt_eb_7, different + 50);
            break;
        case R.id.LP_age_8:
            TOP_10YLuckPillar(LP_cnt_hs_hidden8, LP_cnt_eb_8, different + 60);
            break;
        case R.id.LP_age_9:
            TOP_10YLuckPillar(LP_cnt_hs_hidden9, LP_cnt_eb_9, different + 70);
            break;
        case R.id.LP_age_10:
            TOP_10YLuckPillar(LP_cnt_hs_hidden10, LP_cnt_eb_10, different + 80);
            break;
        case R.id.LP_image_hs_10:
            TOP_10YLuckPillar(LP_cnt_hs_hidden1, LP_cnt_eb_1, 0);
            break;
    }
}
// MLC button click End

public void TOP_10YLuckPillar(int TOP_LP_cnt_hs_hidden, int TOP_LP_cnt_eb,
                              long TOP_LP_title) {
    Button LP_image_hs_out = (Button) findViewById(LP_image_hs);


 // Luck Pillar HS
    int LPLuck_cnt_hd = 0;
    if (TOP_LP_cnt_hs_hidden == 10) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_gui_mlc);
        LPLuck_cnt_hd = 10;
    } else if (TOP_LP_cnt_hs_hidden == 1) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_jia_mlc);
        LPLuck_cnt_hd = 1;
    } else if (TOP_LP_cnt_hs_hidden == 2) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_yi_mlc);
        LPLuck_cnt_hd = 2;
    } else if (TOP_LP_cnt_hs_hidden == 3) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_bing_mlc);
        LPLuck_cnt_hd = 3;
    } else if (TOP_LP_cnt_hs_hidden == 4) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_ding_mlc);
        LPLuck_cnt_hd = 4;
    } else if (TOP_LP_cnt_hs_hidden == 5) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_wu_mlc);
        LPLuck_cnt_hd = 5;
    } else if (TOP_LP_cnt_hs_hidden == 6) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_ji_mlc);
        LPLuck_cnt_hd = 6;
    } else if (TOP_LP_cnt_hs_hidden == 7) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_geng_mlc);
        LPLuck_cnt_hd = 7;
    } else if (TOP_LP_cnt_hs_hidden == 8) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_xin_mlc);
        LPLuck_cnt_hd = 8;
    } else if (TOP_LP_cnt_hs_hidden == 9) {
        LP_image_hs_out.setBackgroundResource(R.mipmap.hs_ren_mlc);
        LPLuck_cnt_hd = 9;
    }


 @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    btn.performClick();
}


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bazi7">

<application
    android:allowBackup="true"
    android:label="XXXX"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:configChanges="screenSize|keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity_LoadData"
        android:label="View Data"
        android:parentActivityName=".MainActivity">
    </activity>
    <activity
        android:name=".EditDataActivity"
        android:label="Edit Data"
        android:parentActivityName=".MainActivity_LoadData">
    </activity>

</application>

</manifest>
...