1

我试图在片段中打开 CardUI,但似乎 getView() 不能用于执行 CardUI 组件和 getActivity()。不过,我在任何地方都找不到任何其他谷歌之类的卡片库。

这个结果在 mcardView 上给了我 NullPointException

private class MyAsyncTask extends AsyncTask<Void, Void, Void> {


        private WeakReference<Tab2Fragment> fragmentWeakRef;

        private MyAsyncTask (Tab2Fragment tab2Fragment) {
            this.fragmentWeakRef = new WeakReference<Tab2Fragment>(tab2Fragment);
        }
        private CardUI mCardView;
        @Override
        protected Void doInBackground(Void... params) {
            // init CardView
            Log.i("Page3","1st");
            try{
            mCardView = (CardUI) getView().findViewById(R.id.cardsview);
            if(mCardView == null){
                Log.i("Page3","Null");
                mCardView = (CardUI) getActivity().findViewById(R.id.cardsview);
            }

            Log.i("Page3","2nd");
            mCardView.setSwipeable(false);
}
}
}

我应该如何解决这个问题?

4

0 回答 0