Android zur Laufzeit den Text im Menü ändern

G

Gast2

Gast
Hallo!

Ich habe ein Menü geschrieben
und will aber zur Laufzeit den Text ändern.

Hier die menu.xml:[XML]<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/values_visibility" android:title="@string/txt_mnu_value_visibility" />
<item android:id="@+id/shout_down" android:title="@string/txt_mnu_shout_down" />
</menu>[/XML]

In MainActivity.java will ich gerne den Text ändern:
Java:
	@Override
	public boolean onOptionsItemSelected(MenuItem item){
		switch(item.getItemId()){
		case R.id.values_visibility:
			valuesOnOff();
			return true;
		case R.id.shout_down:
			shoutDown();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}		
	}

Ich möchte mich auf dei Methode valuesOnOff(); (im Java Code Zeile 5) konzentrieren.
In dieser Methode lasse ich ein Textfeld (der activity_main.xml) ein und ausblenden.
Wenn das Textfeld (mit den Values) eingeblendet ist, so soll der Nutzer im Menü den Eintrag "Werte ausblenden" finden und wenn die Werte ausgeblendet sind dann soll im Menp "Werte einblenden" stehen.
Java:
	private void valuesOnOff() {
		if (valueUnVisible) {
			txv_values.setVisibility(View.VISIBLE);
			valueUnVisible = false;
//			btn_valuesOnOff.setText("Messwerte ausblenden"); // geht gar nicht
		} else {
			txv_values.setVisibility(View.GONE);
//			btn_valuesOnOff.setText("Messwerte einblenden"); // geht gar nicht
			valueUnVisible = true;			
		}
	}

Ich habe schon vergeblich versucht values_visibility (siehe id im xml) zu definieren als Button, Item, View. Aber alles scheint falsch zu sein.

Aber wie komme ich an den Text ran? Hilfe!
Frank
 
G

Gast2

Gast
Hi Schlingel,

dieses Thread hatte ich mir auch schon angeschaut
und damit (erfolglos) rumprobiert.

Aber es ist wirklich die Lösung,
(mittlerer / zweiter Codeblock).

Ich war nur nicht konsequent genug im abtippen / kopieren. ;)
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Zur Laufzeit erstelltes MenuItem an eine View binden Android & Cross-Platform Mobile Apps 1
S Android Absoluter Neuling: EditText zur Laufzeit verändern bzw. über Button Android & Cross-Platform Mobile Apps 2
E Android View zur Laufzeit hinzufügen Android & Cross-Platform Mobile Apps 4
F Android Spinner zur Laufzeit mit verschiedenem Inhalt füllen Android & Cross-Platform Mobile Apps 2
W Edit Text Drawable Icon ändern plus Funktion Android & Cross-Platform Mobile Apps 30
R Google Text-to-Speech Android & Cross-Platform Mobile Apps 5
R wie verwende ich Cloud Text-to-Speech? Android & Cross-Platform Mobile Apps 4
R Android Text-To-Speech Android & Cross-Platform Mobile Apps 4
ruutaiokwu Android In einem Android-“Spinner”-Element GLEICHZEITIG Bild (links) UND Text (rechts) anzeigen Android & Cross-Platform Mobile Apps 0
J Android App - Browser öffnen und Text eingeben/Button click auslösen Android & Cross-Platform Mobile Apps 10
M ImageButton: Bild ausblenden und Text anzeigen Android & Cross-Platform Mobile Apps 2
Flynn Text-File auf externe Speicherkarte schreiben Android & Cross-Platform Mobile Apps 1
F Aufkalbbaren Text Android & Cross-Platform Mobile Apps 4
B Android Text von Android zu PC senden? Android & Cross-Platform Mobile Apps 5
C Android Bei Text "Popup" anzeigen Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
M Android Edittext width passend zum Text Android & Cross-Platform Mobile Apps 1
L Android Theorie: Umwandeln von Text in Morsecode Android & Cross-Platform Mobile Apps 15
R Android Layout Bild mit Text Android & Cross-Platform Mobile Apps 13
N Android Änderung von tabwidget height lässt text verschwinden Android & Cross-Platform Mobile Apps 3
L Android Text aus Textfeld speichern Android & Cross-Platform Mobile Apps 5
J in android app text automatisch kopieren Android & Cross-Platform Mobile Apps 2
S Android Zufällige Text wiedergabe Android & Cross-Platform Mobile Apps 6
K Android schwarzer Bildschirm beim Rendern von Text und Dreiecken Android & Cross-Platform Mobile Apps 9
S Android Canvas - drawText - Update Text in ActionListener Android & Cross-Platform Mobile Apps 8
N Gibt es eine opensource Speech-to-Text engine? Android & Cross-Platform Mobile Apps 3
M Text in txt-Datei schreiben und nach ABC sortieren? Android & Cross-Platform Mobile Apps 2
M Text in Canvas scrollen lassen Android & Cross-Platform Mobile Apps 13
G Text parsen String to Double Android & Cross-Platform Mobile Apps 2
W Menü Header App Absturz bei Headeränderungen Android & Cross-Platform Mobile Apps 49
AGW Android Links im Menü und Namen ändern Android & Cross-Platform Mobile Apps 2
B Android Settings Menü Design Android & Cross-Platform Mobile Apps 2
B Android XML File ein lesen und menü erzeugen Android & Cross-Platform Mobile Apps 1
D Startbildschirm -> Automatisch ins Menü weiterleiten Android & Cross-Platform Mobile Apps 3
A Android Menü Button oben links Android & Cross-Platform Mobile Apps 1
G selbes Menü auf jeder Activity Android & Cross-Platform Mobile Apps 4
N Wie Menü erstellen und Verknüpfen Android & Cross-Platform Mobile Apps 9

Ähnliche Java Themen

Neue Themen


Oben