title: Shared Preferences in Fragment with Kotlin
body: <p>I'm making a counter app in Android using Kotlin. My code is working great in MainActivity but when it comes to fragment it's not working anymore.</p>
  <pre class="lang-kotlin prettyprint-override"><code>class HomeFragment : Fragment()
  {
      private lateinit var homeViewModel: HomeViewModel
  
      @SuppressLint(&quot;SetTextI18n&quot;)
      override fun onCreateView(
          inflater: LayoutInflater,
          container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View?
      {
          /*homeViewModel =
                  ViewModelProvider(this).get(HomeViewModel::class.java)*/
          val root = inflater.inflate(R.layout.fragment_home, container, false)
          val textView: TextView = root.findViewById(R.id.text_home)
          val button: Button = root.findViewById&lt;Button&gt;(R.id.button)
          var nombre = PrefConfing.loadTotalFromPref(this)
          button.setOnClickListener {
              nombre++
              textView.text = &quot;vous l'avez fait $nombre fois&quot;
              PrefConfing.saveTotalTimes(applicationContext, nombre)
          }
  
          return root
      }
  }
  </code></pre>
  <p>This is my Kotlin HomeFragment code, and there is my Java code:</p>
  <pre class="lang-java prettyprint-override"><code>public class PrefConfing {
      private static final String TIMES = &quot;com.example.alllerrr&quot;;
      private static final String PREF_TOTAL_KEY = &quot;pref_total_key&quot;;
  
      public static void saveTotalTimes(Context context, int total) {
          SharedPreferences pref = context.getSharedPreferences(TIMES, Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = pref.edit();
          editor.putInt(PREF_TOTAL_KEY, total);
          editor.apply();
      }
  
      public static int loadTotalFromPref(Context context){
          SharedPreferences pref = context.getSharedPreferences(TIMES, Context.MODE_PRIVATE);
          return pref.getInt(PREF_TOTAL_KEY, 0);
      }
  }
  </code></pre>
  <p>for the var <code>nombre</code> I can't add this to the context and I don't understand why.</p>