How To Access Views Insde The Actionlayout In Menu
I have three menu items which includes same app:actionLayout it has a textview, how can i access the textviews individually through code and set different text for all three textvi
Solution 1:
It would look something like this in OnCreateOptionsMenu
:
getMenuInflater().inflate(R.menu.activity_main_drawer, menu);
LinearLayouttracks= (LinearLayout) menu.findItem(R.id.item_tracks).getActionView();
LinearLayoutrepeat= (LinearLayout) menu.findItem(R.id.item_repeat).getActionView();
LinearLayouttimer= (LinearLayout) menu.findItem(R.id.item_timer).getActionView();
TextViewtvTracks= (TextView) tracks.findViewById(R.id.switchForActionBar);
TextViewtvRepeat= (TextView) repeat.findViewById(R.id.switchForActionBar);
TextViewtvTimer= (TextView) timer.findViewById(R.id.switchForActionBar);
tvTracks.setText("foo");
tvRepeat.setText("bar");
tvTimer.setText("baz");
returntrue;
I'm using LinearLayout
as it's the first element in menu_text_layout.xml
Post a Comment for "How To Access Views Insde The Actionlayout In Menu"