SHARE
TWEET

Untitled

a guest Sep 11th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.favorite.fragment;
  2.  
  3.  
  4. import android.annotation.SuppressLint;
  5. import android.content.Intent;
  6. import android.database.Cursor;
  7.  
  8. import android.os.AsyncTask;
  9. import android.os.Build;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15.  
  16.  
  17. import androidx.annotation.RequiresApi;
  18. import androidx.fragment.app.Fragment;
  19. import androidx.recyclerview.widget.LinearLayoutManager;
  20. import androidx.recyclerview.widget.RecyclerView;
  21.  
  22. import com.example.favorite.R;
  23. import com.example.favorite.adapter.MovieTvFavAdapter;
  24.  
  25. import java.lang.ref.WeakReference;
  26. import java.util.Objects;
  27.  
  28. import static com.example.favorite.DbContract.MovieEntry.CONTENT_URI;
  29.  
  30.  
  31. /**
  32.  * A simple {@link Fragment} subclass.
  33.  */
  34. public class Favorit_FilmFragment extends Fragment  {
  35.     MovieTvFavAdapter mMovieTvFavAdapter;
  36.     Cursor mList;
  37.     RecyclerView mRecyclerView;
  38.     public Favorit_FilmFragment() {
  39.         // Required empty public constructor
  40.     }
  41.  
  42.  
  43.     @Override
  44.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  45.                              Bundle savedInstanceState) {
  46.         // Inflate the layout for this fragment
  47.         View v = inflater.inflate(R.layout.fragment_favorit__film, container, false);
  48.         mRecyclerView = v.findViewById(R.id.rv_movie);
  49.  
  50.         mMovieTvFavAdapter = new MovieTvFavAdapter(getContext());
  51.         Log.d("creattemovie", String.valueOf(mMovieTvFavAdapter));
  52.         mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL,false));
  53.         mRecyclerView.setAdapter(mMovieTvFavAdapter);
  54.         new LoadMovieFav().execute();
  55.         return v;
  56.     }
  57.  
  58.     @SuppressLint("StaticFieldLeak")
  59.     public class LoadMovieFav extends AsyncTask<Void,Void,Cursor>{
  60.         @Override
  61.         protected void onPreExecute() {
  62.             super.onPreExecute();
  63.         }
  64.  
  65.         @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  66.         @Override
  67.         protected Cursor doInBackground(Void... voids) {
  68.             Log.d("loadmovie", String.valueOf(CONTENT_URI));
  69.             return Objects.requireNonNull(getContext()).getContentResolver().query(CONTENT_URI,null,null,null,null);
  70.         }
  71.  
  72.         @Override
  73.         protected void onPostExecute(Cursor cursor) {
  74.             super.onPostExecute(cursor);
  75.             mList = cursor;
  76.             Log.d("cursor", String.valueOf(mList));
  77.             mMovieTvFavAdapter.setmMovieTvItems(mList);
  78.             mMovieTvFavAdapter.notifyDataSetChanged();
  79.  
  80.         }
  81.     }
  82.  
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top