Issue
I want to show creation date of a note. I'm using data binding , I need to use toString function to have a formatted date string, but toString function takes a string as argument. Here is the code:
<data>
<import type="com.example.path.myproject.model.Note"/>
<variable
name="noteViewModel"
type="com.example.path.myproject.note.NoteViewModel" />
</data>
<TextView
android:id="@+id/createdDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@{noteViewModel.note.createDate.toString("dd/mm/yyyy")}"
/>
But I have an error, because I can't use double quotes inside there. How can I solve it?
Solution
Put that attribute in single quotes, and then you can use double quotes inside it.
<TextView
android:id="@+id/createdDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text='@{noteViewModel.note.createDate.toString("dd/mm/yyyy")}'
/>
Answered By - Leo Aso
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.