android getActivity.findViewById獲取ListView 返回NULL

在控件ID正確的狀況下,檢查是否在實例化佈局文件以後,獲取LISTVIEW,ide

先inflate找layout下佈局文件,並實例化後才能得到Listview的ID佈局

demo:spa

public class FragmentPage extends Fragment {
View view = null; io

    @Override
    @SuppressLint("HandlerLeak")
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { class

                 view = inflater.inflate(R.layout.fragment_2, null); List

               

            // @此處獲取使用view.findViewById(list的ID);fragment

      

       //最後返回加載後的佈局文件
        return view; layout

    } demo

}文件

相關文章
相關標籤/搜索