像onCreateViewHolder()
,onBindViewHolder()
,onAttachedToRecyclerView()
這樣的函數永遠不會被調用。這是我想要做的。Android,適配器中的函數永遠不會被調用
- 交換機從
MainActivity
到RecyclerViewActivity
當點擊Button1
,和負載fragment_recyclerview
成RecyclerViewActivity
switch(id) {
case R.id.aboutMeButton:
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainer, AboutMeFragment.newInstance()).addToBackStack(null).commit();
break;
case R.id.task1Button:
intent = new Intent(this, RecyclerViewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
break;
default:
break;
}
FragmentViewActivity.onCreate()
FragmentViewActivity.onCreate()
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recyclerview);
getSupportFragmentManager().beginTransaction().replace(R.id.recyclerViewContainer, RecyclerViewFragment.newInstance()).commit();
Log.d("AAA", "RecyclerViewActivity.onCreate()");
}
RecyclerViewFragment.onCreateView()
:
RecyclerViewFragment.onCreateView(){
final View rootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
movieData = new MovieData();
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.cardViewContainer);
// Log.d("AAA", "mRecyclerView = " + mRecyclerView.getId());
// 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);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
Log.d("AAA", "getActivity() = " + getActivity().toString());
Log.d("AAA", "movieList size = " + movieData.getMoviesList().size());
// specify an adapter (see also next example)
mAdapter = new MovieDataAdapter(getActivity(), movieData.getMoviesList());
mRecyclerView.setAdapter(mAdapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
Adapter.getItemCount()
返回30,但是,功能在構造函數以外的其他構造函數永遠不會被調用,這爲我留下了一個純粹的空白屏幕 。我不知道這是怎麼回事
看看'onCreateView()'方法中的'return'語句。你沒有返回你剛纔設置的所有東西。 –