Recently I came across the use-case of using tools:context
in my layout files for activities.
I learned that I can use it to associate an Activity class file to my layout file.
But how can I use it to associate a Fragment class file to any layout?
Bacuase as I have tried, it is only showing Activity list in autocomplete suggestion.
There is a bug in Android Studio, you have to write it manually, it will appear red(indicating it's unresolved) until you finish typing, then it will appear in green
Have you tried it doing like this:
Let's say Relative layout
is your parent layout in your fragment's
layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Folder.Fragment" >
Now this .xml file will be associated with your .Fragment class
which is a fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With