@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    weatheradapter = new ForecastAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    listview = (ListView) rootView.findViewById(R.id.listview_weather);
    listview.setAdapter(weatheradapter);
    listview.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
              String locationSetting = Utility.getPreferredLocation(getActivity());
              ((Callback) getActivity())
                  .onItemSelected(
                      Weathercontract.WeatherEntry.buildWeatherLocationWithDate(
                          locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
          }
        });
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
      mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    weatheradapter.setUseTodayLayout(mUseTodayLayout);
    return (rootView);
  }
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);
    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    mlistView = (ListView) rootView.findViewById(R.id.listview_forecast);
    View emptyView = rootView.findViewById(R.id.forecast_fragment_empty_textview);
    mlistView.setEmptyView(emptyView);
    mlistView.setAdapter(mForecastAdapter);

    mlistView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            if (cursor != null) {
              String locationSetting = Utility.getPreferredLocation(getActivity());
              ((Callback) getActivity())
                  .onItemSelected(
                      WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                          locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
          }
        });

    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
      mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
  }
 public void setUseTodayLayout(boolean useTodayLayout) {
   mUseTodayLayout = useTodayLayout;
   if (mForecastAdapter != null) {
     mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    String locationSetting = Utility.getPreferredLocation(getActivity());

    // Sort order:  Ascending, by date.
    //        String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
    //        Uri weatherForLocationUri =
    // WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
    //                locationSetting, System.currentTimeMillis());

    //        Cursor cur = getActivity().getContentResolver().query(weatherForLocationUri,
    //                null, null, null, sortOrder);

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.

    // However, we cannot use FLAG_AUTO_REQUERY since it is deprecated, so we will end
    // up with an empty list the first time we run.

    //       // The CursorAdapter will take data from our cursor and populate the ListView.
    //      mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    //// The ForecastAdapter will take data from a source and
    //               // use it to populate the RecyclerView it's attached to.
    //        mForecastAdapter = new ForecastAdapter(getActivity());

    rootView = inflater.inflate(R.layout.fragment_main, container, false);
    //        mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    //        View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    //        mListView.setEmptyView(emptyView);
    //        mListView.setAdapter(mForecastAdapter);

    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_forecast);
    // Set the layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    View emptyView = rootView.findViewById(R.id.recyclerview_forecast_empty);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // The ForecastAdapter will take data from a source and
    // use it to populate the RecyclerView it's attached to.
    mForecastAdapter =
        new ForecastAdapter(
            getActivity(),
            new ForecastAdapter.ForecastAdapterOnClickHandler() {
              @Override
              public void onClick(Long date, ForecastAdapter.ForecastAdapterViewHolder vh) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity())
                    .onItemSelected(
                        WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                            locationSetting, date),
                        vh);
                // I could have sent the position back directly instead of the ViewHolder
                mPosition = vh.getAdapterPosition();
              }
            },
            emptyView,
            mChoiceMode);

    // specify an adapter (see also next example)
    mRecyclerView.setAdapter(mForecastAdapter);

    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mRecyclerView.addOnScrollListener(
            new RecyclerView.OnScrollListener() {
              @TargetApi(Build.VERSION_CODES.HONEYCOMB)
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int max = parallaxView.getHeight();
                if (dy > 0) {
                  parallaxView.setTranslationY(
                      Math.max(-max, parallaxView.getTranslationY() - dy / 2));
                } else {
                  parallaxView.setTranslationY(
                      Math.min(0, parallaxView.getTranslationY() - dy / 2));
                }
              }
            });
      }
    }

    final AppBarLayout appbarView = (AppBarLayout) rootView.findViewById(R.id.appbar);
    if (null != appbarView) {
      ViewCompat.setElevation(appbarView, 0);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mRecyclerView.addOnScrollListener(
            new RecyclerView.OnScrollListener() {
              @TargetApi(Build.VERSION_CODES.LOLLIPOP)
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (0 == mRecyclerView.computeVerticalScrollOffset()) {
                  appbarView.setElevation(0);
                } else {
                  appbarView.setElevation(appbarView.getTargetElevation());
                }
              }
            });
      }
    }

    //        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    //
    //            @Override
    //            public void onItemClick(AdapterView adapterView, View view, int position, long l)
    // {
    //                // CursorAdapter returns a cursor at the correct position for getItem(), or
    // null
    //                // if it cannot seek to that position.
    //                Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
    //                if (cursor != null) {
    //                    String locationSetting = Utility.getPreferredLocation(getActivity());
    //
    //                    ((Callback) getActivity())
    //
    // .onItemSelected(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
    //                                    locationSetting, cursor.getLong(COL_WEATHER_DATE)
    //                            ));
    //
    //                    mPosition = position;
    //                }
    //            }
    //        });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null) {
      if (savedInstanceState.containsKey(SELECTED_KEY)) {
        // The Recycler View probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
      }
      mForecastAdapter.onRestoreInstanceState(savedInstanceState);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
  }
 public void setUseTodayLayout(boolean useTodayLayout) {
   mUseTodayLayout = useTodayLayout;
   if (weatheradapter != null) {
     weatheradapter.setUseTodayLayout(mUseTodayLayout);
   }
 }