第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Fragment Recyclerview onCreateView、onViewCreated

Fragment Recyclerview onCreateView、onViewCreated

開滿天機 2021-10-13 13:59:39
我應(yīng)該在 onCreateView、onViewCreated 還是 onActivityCreated 中初始化我的回收視圖?這三個之間有什么區(qū)別,我搜索了解釋,但有些人說使用 onCreateView ,有些人說使用 onViewCreated 或 onActivityCreated 并且只使用 onCreateView 來膨脹布局?這是我的代碼@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,                         Bundle savedInstanceState) {    // Inflate the layout for this fragment    View rootView = inflater.inflate(R.layout.fragment_tab1, container, false);    recyclerViewSongs = rootView.findViewById(R.id.recyclerViewSongs);    initRecyclerView();    Log.e(TAG, "onCreateView called!");    return rootView;}private void initRecyclerView() {    Main.musicList = Main.songs.songs;    // Connects the song list to an adapter    // (Creates several Layouts from the song list)    allSongsAdapter = new AllSongsAdapter(getContext(), Main.musicList);    final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());    recyclerViewSongs.setLayoutManager(linearLayoutManager);    recyclerViewSongs.setHasFixedSize(true);    recyclerViewSongs.setAdapter(allSongsAdapter);    recyclerViewSongs.addOnItemTouchListener(new OnItemClickListeners(getContext(), new OnItemClickListeners.OnItemClickListener() {            @TargetApi(Build.VERSION_CODES.O)            @Override            public void onItemClick(View view, int position) {                Toast.makeText(getContext(), "You Clicked position: " + position, Toast.LENGTH_SHORT).show();                if (! Main.songs.isInitialized())                    return;                //Start playing the selected song.                playAudio(position);            }        }));}
查看完整描述

2 回答

?
慕斯王

TA貢獻1864條經(jīng)驗 獲得超2個贊

onCreateView()將是最佳選擇,因為您正在使用Fragment. 所不同的是onCreateView()Fragment等價的onCreate()各種活動和運行期間View創(chuàng)建,但onViewCreated()運行后View已創(chuàng)建。

并在完成方法onActivityCreated()之后調(diào)用


查看完整回答
反對 回復(fù) 2021-10-13
?
慕工程0101907

TA貢獻1887條經(jīng)驗 獲得超5個贊

設(shè)置 RecyclerView 的最佳級別是在 onCreateView() 中,在 Activity 的情況下相當于 onCreate() 因為 RecyclerView 需要快速以免使 UI 變得遲鈍。因此,onViewCreated() 中的 RecyclerView 會使 UI 在填充 UI 之前變得緩慢。


查看完整回答
反對 回復(fù) 2021-10-13
  • 2 回答
  • 0 關(guān)注
  • 325 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號