0
嗨,任何人都可以幫助我,請讓我很難做出這項工作,並一直在嘗試很多方法來使這項工作,但每次我運行此代碼它只顯示beginner1Check,即使我打開布爾爲真。任何人都可以幫助我嗎?沒有正確加載按鈕
這裏是我的代碼
的.java
public void initialize(){
SharedPreferences beginner1Prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean beginner1_pref = beginner1Prefs.getBoolean("Beginner1", false);
if (beginner1_pref == false){
beginner1Check = (Button) findViewById(R.id.btnBeginner1Check);
beginner1Check.setOnClickListener(myOnlyhandler);
} else if (beginner1_pref == true){
beginner1 = (Button) findViewById(R.id.btnBeginner1);
beginner1.setOnClickListener(myOnlyhandler);
}
btnLogo = (Button) findViewById(R.id.btnLogo);
beginner2 = (Button) findViewById(R.id.btnBeginner2);
beginner3 = (Button) findViewById(R.id.btnBeginner3);
beginner4 = (Button) findViewById(R.id.btnBeginner4);
beginner5 = (Button) findViewById(R.id.btnBeginner5);
beginner6 = (Button) findViewById(R.id.btnBeginner6);
beginner7 = (Button) findViewById(R.id.btnBeginner7);
beginner8 = (Button) findViewById(R.id.btnBeginner8);
beginner9 = (Button) findViewById(R.id.btnBeginner9);
btnLogo.setOnClickListener(myOnlyhandler);
beginner2.setOnClickListener(myOnlyhandler);
beginner3.setOnClickListener(myOnlyhandler);
beginner4.setOnClickListener(myOnlyhandler);
beginner5.setOnClickListener(myOnlyhandler);
beginner6.setOnClickListener(myOnlyhandler);
beginner7.setOnClickListener(myOnlyhandler);
beginner8.setOnClickListener(myOnlyhandler);
beginner9.setOnClickListener(myOnlyhandler);
}
XML>的prefs.xml
<CheckBoxPreference
android:title="Beginner1"
android:defaultValue="false"
android:key="Beginner1"
android:summary="Beginner1" />
你想做什麼?提供更多細節。 – Naddy
我想加載button1,如果beginner1_pref = true,然後隱藏button2然後在beginner1_pref = false顯示button2然後隱藏button1 – John
給你的'活動'代碼。 – Naddy