私はViewPager、RecyclerView、およびContentProviderの基本設定を実装しました。問題なくデータを照会できるようですが、ViewPagerタブでRecyclerViewを使用してコンテンツを表示することができません。RecyclerViewがViewPagerタブにデータを入力しない
完全なコードはここにあります - https://github.com/sudhirkhanger/PopularMovies
public class FavoriteFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movie_list, container, false);
// Set column size to 2 for default and portrait
// and 3 for landscape orientations
int column = Integer.parseInt(getString(R.string.grid_portrait));
if (getResources().getConfiguration().orientation == 1) {
column = Integer.parseInt(getString(R.string.grid_portrait));
} else if (getResources().getConfiguration().orientation == 2) {
column = Integer.parseInt(getString(R.string.grid_landscape));
}
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), column));
ArrayList<Movie> mMovieArrayList = new ArrayList<Movie>();
ContentResolver resolver = getActivity().getContentResolver();
Cursor cursor =
resolver.query(MovieContract.MovieEntry.CONTENT_URI,
null,
null,
null,
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String title = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.TITLE));
String movie_id = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.MOVIE_ID));
String poster = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.POSTER));
String backdrop = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.BACKDROP));
String overview = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.OVERVIEW));
String vote_average = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.VOTE_AVERAGE));
String release_date = cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.DATE));
Movie movie = new Movie(title, release_date, poster,
vote_average, overview, backdrop, movie_id);
mMovieArrayList.add(movie);
} while (cursor.moveToNext());
}
}
if (cursor != null)
cursor.close();
for (Movie movie : mMovieArrayList) {
Log.d("FavoriteFragment List", movie.getTitle());
}
mMovieAdapter = new MovieAdapter(getActivity(), mMovieArrayList);
mMovieAdapter.notifyDataSetChanged();
mRecyclerView.setAdapter(mMovieAdapter);
return rootView;
}
public static FavoriteFragment newInstance() {
Bundle args = new Bundle();
FavoriteFragment fragment = new FavoriteFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public void onResume() {
super.onResume();
mRecyclerView.setAdapter(mMovieAdapter);
mMovieAdapter.notifyDataSetChanged();
}
RecyclerView mRecyclerView;
MovieAdapter mMovieAdapter;
}
そのArrayListのデータが含まれているの下にあなたが見ることができるように。
04-25 22:02:36.216 4718-4718/com.sudhirkhanger.app.popularmoviesstageone W/FragmentManager: moveToState: Fragment state for PopularFragment{d7cf0b6 #1 id=0x7f0c006b} not updated inline; expected state 3 found 2
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Whiplash
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Batman v Superman: Dawn of Justice
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Star Wars: The Force Awakens
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: The Shawshank Redemption
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: The Godfather
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Interstellar
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Captain America: Civil War
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: The Jungle Book
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: The Revenant
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Jurassic World
04-25 22:02:37.757 4718-4718/com.sudhirkhanger.app.popularmoviesstageone D/FavoriteFragment List: Mad Max: Fury Road
ありがとうございましたチャドが問題を解決しませんでした。 –