栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

初始应用加载时未加载ViewPager数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

初始应用加载时未加载ViewPager数据

像这样更新两个类,可能对您有帮助!

fetchDataclass:

public class fetchData extends AsyncTask<Void,Void,Void> {    String data ="";    String factTitle = "";    String factDesc = "";    String factImg ="";    String singleParsed ="";    String DoubleParsed ="";    String tripleParsed ="";    Activity mContext;    TextView mfactTitle,mfactDesc;    ImageView mfactImg;    ProgressBar mProgressbar;   public fetchData(Activity context,TextView mfactTitle,TextView    mfactDesc,ImageView mfactImg,ProgressBar mProgressbar){   this.context=context;   this.mfactTitle=mfactTitle;    this.mfactDesc=mfactDesc;   this.mfactImg=mfactImg;   this.mProgressbar=mProgressbar;   }    @Override    protected Void doInBackground(Void... voids) {        try { URL url = new URL("http://xxxxxx.com/api"); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); InputStream inputStream = httpURLConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line = ""; while(line != null){     line = bufferedReader.readLine();     data = data + line; } JSonArray JA = new JSonArray(data); for(int i =0 ;i <JA.length(); i++){     JSonObject JO = (JSONObject) JA.get(i);     singleParsed =  ""+JO.get("fact");     DoubleParsed =  ""+JO.get("factdesc");     tripleParsed =  ""+JO.get("img");     factTitle = factTitle + singleParsed;     factDesc  = factDesc + DoubleParsed;     factImg  = factImg + tripleParsed; }        } catch (MalformedURLException e) { e.printStackTrace();        } catch (IOException e) { e.printStackTrace();        } catch (JSonException e) { e.printStackTrace();        }        return null;    }    @Override    protected void onPostExecute(Void aVoid) {        super.onPostExecute(aVoid);        mfactImg.setVisibility(View.VISIBLE);        mfactTitle.setText(this.factTitle);        mfactDesc.setText(this.factDesc);     Picasso.get().load(factImg).placeholder(R.drawable.defaultthumb).into(mfactImg);       mProgressBar.setVisibility(View.INVISIBLE);    }}

PlaceHolder片段:

public static PlaceholderFragment newInstance(int sectionNumber) { PlaceholderFragment fragment = new PlaceholderFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); fragment.setArguments(args); return fragment;        }        @Override        public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); factTitle = (TextView) rootView.findViewById(R.id.fact_label); factDesc = (TextView) rootView.findViewById(R.id.fact_description); factImg = (ImageView) rootView.findViewById(R.id.imageView); loader = (ProgressBar) rootView.findViewById(R.id.progressBar); fetchData process = new fetchData(getActivity(),factTitle,factDesc,factImg,loader); process.execute(); return rootView;        }    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470099.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号