I want to call my Util class method in layout.xml file like
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{PreferenceUtil.getSavedUser().fullName}"/>
I have imported PreferenceUtil
<import type="com.amelio.utils.PreferenceUtil"/>
And PreferenceUtil.class has some methods.
public class PreferenceUtil {
public static LoginResponse getSavedUser() {
SharedPreferences sf = Amelio.getInstance().getSharedPreferences(PREF, Context.MODE_PRIVATE);
String userJson = sf.getString(PREF_USER_DATA, null);
if (userJson == null || userJson.equals("")) {
return null;
}
return new Gson().fromJson(userJson, LoginResponse.class);
}
}
Issue
Found data binding errors.
****/ data binding error ****msg:cannot find method getSavedUser() in class com.amelio.utils.PreferenceUtil
file:D:\Khemraj\_AndroidStudioWorkspace_\amelioFinal\app\src\main\res\layout\activity_cart.xml
loc:94:40 - 94:68
****\ data binding error ****
Is this even possible, also suggest if this is recommended or not.
Html.fromHtml()in various book examples. IsLoginResponsemarked aspublic? Also, please do not do I/O (getSharedPreferences()) and data parsing (new Gson().fromJson()) on the main application thread, as you are here.can not find getSavedUserLoginResponseis notpublic, it is possible that the data binding framework cannot really resolve that method reference.<import>element in the<data>to declare thePreferenceUtiltype, using the fully-qualified class name. Then, your binding expressions can refer to the static methods on that class.