片段中的CardUI不能使用getView

时间:2013-10-06 09:23:11

标签: android android-fragments

我试图在片段中打开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);
}
}
}

我该如何解决这个问题?

0 个答案:

没有答案