Check Button ist unchecked trotz setChecked(true)

G

Gast2

Gast
Hi.

Ich habe einen Checkbutton:
[XML] <CheckBox
android:id="@+id/ckb_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/txt_ckb_id" />[/XML]

Und setze ihn auf checked = true:
Java:
private CheckBox ckb_id;
ckb_id = (CheckBox) findViewById(R.id.ckb_id);
ckb_id.setOnClickListener(this);
ckb_id.setChecked(true);

Und trotz dem wird er nicht als checked angezeigt
(sondern ohne Häckchen).

Warum ist die Check Box nicht aktiviert???

Frank
 
G

Gast2

Gast
Java:
	@Override
	public void onClick(View buttonView) {
		switch (buttonView.getId()) {
			
		case R.id.ckb_id:
			editor = sharedPreferences.edit();
			if (ckb_id.isChecked()) {		// wird aktiviert
				ckb_id.setChecked(true);
				editor.putBoolean("bool_ckb_id", true);
			} else {						// wird deaktiviert
				ckb_id.setChecked(false);
				editor.putBoolean("bool_ckb_id", false);
			}
			editor.commit();
			break;

		default:
			break;
		}

Nichts desto trotz wird die Check Box zur Geburt der Activity als unchecked gezeigt, obwohl das Gegenteil gefordert?!
 

schlingel

Gesperrter Benutzer
Hm, der Code sieht eigentlich in Ordnung aus.

Was passiert wenn du die Reihenfolge setChecked und setOnClickListener vertauscht?
 
G

Gast2

Gast
Ja, ich bin soeben sogar nochmal mit breackpoints über alles drüber gegangen.
Und,... Er geht beim Start nicht in das onClick -Ereignis (wie es sein sollte).

Die Variable ckb_id wird auch nirgendwo anders benutzt.
(nur wie es oben zu sehen ist)
 
Zuletzt bearbeitet von einem Moderator:
Ähnliche Java Themen
  Titel Forum Antworten Datum
B Android ListView set custom check Image and delete Android & Cross-Platform Mobile Apps 0
T Android Studio: Einen Button in einer For Schleife verwenden Android & Cross-Platform Mobile Apps 2
W App deinstallieren per Button & Andere App Öffnen per Button Android & Cross-Platform Mobile Apps 24
W Apk automatisch installieren per Button Android & Cross-Platform Mobile Apps 55
W aus Fragmente in andere Klasse wechseln mit Button Android & Cross-Platform Mobile Apps 3
T App updaten via Button Android & Cross-Platform Mobile Apps 10
AGW Android Teilen Button ändern Android & Cross-Platform Mobile Apps 14
A Button in SurfaceView integrieren Android & Cross-Platform Mobile Apps 10
J Android App - Browser öffnen und Text eingeben/Button click auslösen Android & Cross-Platform Mobile Apps 10
L Button zum Quadrad zwingen Android & Cross-Platform Mobile Apps 2
S Android Absoluter Neuling: EditText zur Laufzeit verändern bzw. über Button Android & Cross-Platform Mobile Apps 2
L Dialog anzeigen wenn auf Button gedrückt wird. Android & Cross-Platform Mobile Apps 4
S Android ListFragment & ArrayAdapter - Button-Werte werden vergessen Android & Cross-Platform Mobile Apps 0
B Android Abfragen wie lang ein Button gedrückt wurde Android & Cross-Platform Mobile Apps 2
J Android button mithilfe einer Methode automatisch erstellen Android & Cross-Platform Mobile Apps 6
A AlertDialog Enable Button Android & Cross-Platform Mobile Apps 1
J Button array ID Problem Android & Cross-Platform Mobile Apps 2
D Android Activity wechseln per Button Android & Cross-Platform Mobile Apps 3
B Android ringProgressDialog nach Erfolg Button einfärben Android & Cross-Platform Mobile Apps 2
A Android Menü Button oben links Android & Cross-Platform Mobile Apps 1
B Mit Button GeräteEinstellung des Handys öffnen Android & Cross-Platform Mobile Apps 3
M Android Android "Up-Button" extra definieren? Android & Cross-Platform Mobile Apps 1
K Problem mit arraylist und button Android & Cross-Platform Mobile Apps 16
T Button aktivieren per Qullcode... Android & Cross-Platform Mobile Apps 3
T Button geht net... Android & Cross-Platform Mobile Apps 2
D Man sieht nicht ob Button gedrückt wurde! Android & Cross-Platform Mobile Apps 10
K Grafik Tablerow, Button erstreckt sich in der gesamten Breite trotz Beschrenkung durch (max)width Android & Cross-Platform Mobile Apps 2
G Button ein Wert zuweisen Android & Cross-Platform Mobile Apps 5
M 20 Image Button für jede Auflösung positionieren Android & Cross-Platform Mobile Apps 3
B Android Button erstellen nach Vorlage Android & Cross-Platform Mobile Apps 4
L Android Button mit Pfeil nach rechts Android & Cross-Platform Mobile Apps 1
M Einzel Verarbeitung welcher Button angeklickt wurde? Android & Cross-Platform Mobile Apps 6
G Back-Button Methode überschreiben Android & Cross-Platform Mobile Apps 2
P Android Option Button Android & Cross-Platform Mobile Apps 4
G Android Button mit Bild Android & Cross-Platform Mobile Apps 4
W Android App Programmierung - Button ganz transparent machen Android & Cross-Platform Mobile Apps 3
L Custom Dialog Button event Android & Cross-Platform Mobile Apps 2
J Button rechtsbündig Android & Cross-Platform Mobile Apps 5
A Android Button Array? Android & Cross-Platform Mobile Apps 6
P Android Button mit bild versehen Android & Cross-Platform Mobile Apps 4
J "Button" auf List erstellen Android & Cross-Platform Mobile Apps 4
U Fire button und Command.BACK, 1 kommen sich in die quere Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben