I m creating an app in which an user must connect himself. I m trying to implement a menu, in which the first item text would be the name of the connected user and once clicked on, it would bring to the user profile. To store the connected user information, I created my own subclass of android.app.Application, which contains, amongst others, the connected user:
private User currUser; public User getCurrUser() { return this.currUser; } public void setCurrUser(User currUser) { this.currUser = currUser; }
I was wondering how can I access to this global variable, in my menu XML file, so that the title of the first item would be the connected user name? Logically, I would do something like that:
<item android:id="@+id/action_profil" android:title=(MyApp)this.getApplication().getCurrUser().getM_UserName() android:orderInCategory="100" app:showAsAction="never" />
But I know this is not doable in XML. How would I do this? Perhaps, I should re-title the item somewhere else? I found a solution where I change the title in the onCreateOptionsMenu event of the activity, but is there a better way than having to change the item title in every activity containing the menu?
Edit - Here s my XML file
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.aramjeremie.liftm8.HomeActivity"> <item android:id="@+id/action_profil" android:title="Mon_Nom" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_home" android:title="@string/action_home" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_notifications" android:title="@string/action_notifications" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_passenger" android:title="@string/action_passenger" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_driver" android:title="@string/action_driver" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_search" android:title="@string/action_search" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_settings" android:title="@string/action_settings" android:orderInCategory="100" app:showAsAction="never" /> <item android:id="@+id/action_signOut" android:title="@string/action_signOut" android:orderInCategory="100" app:showAsAction="never" /> </menu>
Thanks.