title: on recycler view item click new fragment
body: <p>I have a code for opening an activity on clicking an item in recycler view with shared preferences. I am trying to do the same with fragments. </p>
  
  <p>here is the code with activity.</p>
  
  <pre><code>listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
  
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                  switch(position){
  
                      case 0: {
  
                          startActivity(new Intent(WeekActivity.this, DayDetail.class));
  
                          sharedPreferences.edit().putString(SEL_DAY, "Monday").apply();
  
                          break;
  
                      }
  
                      case 1: {
  
                          startActivity(new Intent(WeekActivity.this, DayDetail.class));
  
                          sharedPreferences.edit().putString(SEL_DAY, "Tuesday").apply();
  
                          break;
  
                      }
  
                      case 2: {
  
                          startActivity(new Intent(WeekActivity.this, DayDetail.class));
  
                          sharedPreferences.edit().putString(SEL_DAY, "Wednesday").apply();
  
                          break;
  
                      }
  
                      case 3: {
  
                          startActivity(new Intent(WeekActivity.this, DayDetail.class));
  
                          sharedPreferences.edit().putString(SEL_DAY, "Thursday").apply();
  
                          break;
  
                      }
  
                      case 4: {
  
                          startActivity(new Intent(WeekActivity.this, DayDetail.class));
  
                          sharedPreferences.edit().putString(SEL_DAY, "Friday").apply();
  
                          break;
  
                      }
  
                      case 5: {
  
                          startActivity(new Intent(WeekActivity.this, DayDetail.class));
  
                          sharedPreferences.edit().putString(SEL_DAY, "Saturday").apply();
  
                          break;
  
                      }
  
                      default:break;
                  }
  
              }
  
          });
  </code></pre>
  
  <p>I have tried doing it in fragments</p>
  
  <pre><code>listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
  
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                  Fragment selectedFragment = null;
  
                  switch (position) {
  
                      case 0: {
  
                          selectedFragment = Timetable.newInstance();
  
                          sharedPreferences.edit().putString(SEL_DAY, "Monday").apply();
  
                          break;
  
                      }
  
                      case 1: {
  
                          selectedFragment = Timetable.newInstance();
  
                          sharedPreferences.edit().putString(SEL_DAY, "Tuesday").apply();
  
                          break;
  
                      }
  
                      case 2: {
  
                          selectedFragment = Timetable.newInstance();
  
                          sharedPreferences.edit().putString(SEL_DAY, "Wednesday").apply();
  
                          break;
  
                      }
  
                      case 3: {
  
                          selectedFragment = Timetable.newInstance();
  
                          sharedPreferences.edit().putString(SEL_DAY, "Thursday").apply();
  
                          break;
  
                      }
  
                      case 4: {
  
                          selectedFragment = Timetable.newInstance();
                          sharedPreferences.edit().putString(SEL_DAY, "Friday").apply();
  
                          break;
  
                      }
  
                      case 5: {
  
                          selectedFragment = Timetable.newInstance();
                          sharedPreferences.edit().putString(SEL_DAY, "Saturday").apply();
  
                          break;
  
                      }
  
                      default:
                          break;
  
                  }
                  FragmentTransaction transaction = ((AppCompatActivity) getActivity()).getSupportFragmentManager().beginTransaction();
                  transaction.replace(R.id.rel_layout, selectedFragment);
                  transaction.commit();
  
  
              }
  
          });
  </code></pre>
  
  <p>Where did i go wrong? What changes should i make? I get no errors. At the same time nothing happens. Help me out :)</p>