no carga el boton correctamente
Frecuentes
Visto 49 veces
0
Hi can anyone help me please I'm having a hard time making this work and been trying so many ways to make this work but everytime I run this code it only shows the beginner1Check even if I turn the boolean to true. can anyone help me please?
aquí están mis códigos
.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" />
1 Respuestas
0
The problem is that you haven't made the second Button
invisible. You have just initialized the first Button
but your second Button
obviously exists in your layout. It won't hide unless you explicitly hide it. Modify your code like this:
if (beginner1_pref == false){
beginner1Check = (Button) findViewById(R.id.btnBeginner1Check);
beginner1 = (Button) findViewById(R.id.btnBeginner1);
beginner1.setVisibility(View.INVISIBLE);//You can replace it with VIEW.GONE depending on your needs.
beginner1Check.setOnClickListener(myOnlyhandler);
} else if (beginner1_pref == true){
beginner1 = (Button) findViewById(R.id.btnBeginner1);
beginner1Check = (Button) findViewById(R.id.btnBeginner1Check);
beginner1Check.setVisibility(View.INVISIBLE);
beginner1.setOnClickListener(myOnlyhandler);
}
respondido 28 nov., 13:09
@Naddy Please do not tell people they must accept answers. Eso no es cierto en absoluto. - Andrew barbero
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android sharedpreferences or haz tu propia pregunta.
What are you trying to do?? Give more details. - Naddy
I'm trying to load button1 if beginner1_pref = true and hide button2 then on beginner1_pref = false show button2 then hide button1 - Aldy
Entrega tu
Activity
código. - Naddy