zoukankan      html  css  js  c++  java
  • 在子线程中更新ProgressBar为null

    1   就是自己ProgressBar有两个,我在findViewbyId时填了另一个,所以tm的搞了半天才找到错误。

    2 另外有个问题,先写在这,记得以前遇到过,忘了咋解决的了

    这里在另一个子线程中修改pb_antivirus,这两个线程的步调可能不一致的啊,但是为啥能够正常执行?有大神解决吗

    private void initUI() {
            iv_antivirus_bg=(ImageView)findViewById(R.id.iv_antivirus_bg);
            iv_antivirus_bg1=(ImageView)findViewById(R.id.iv_antivirus_bg1);
            tv_antivirus=(TextView)findViewById(R.id.tv_antivirus);
            pb_antivirus=(ProgressBar)findViewById(R.id.pb_antivirus);
            ll_layout=(LinearLayout)findViewById(R.id.ll_layout);
        }

    private
    void initData() { new Thread(){ public void run() { mAntivirusList=AntivirusDao.getAntivirus(); PackageManager pm=getPackageManager(); List<PackageInfo> packageInfoList=pm.getInstalledPackages( PackageManager.GET_SIGNATURES+PackageManager.GET_UNINSTALLED_PACKAGES); mAntivirusListT=new ArrayList<Antivirus>(); pb_antivirus.setMax(packageInfoList.size()); for(PackageInfo pif:packageInfoList){ Antivirus antivirus=new Antivirus(); //病毒对象个体 Signature[] signatures=pif.signatures; Signature signature=signatures[0]; String string=signature.toCharsString(); String md5=MD5Util.encoder(string); for(Antivirus a:mAntivirusList){ if(a.getMd5().equals(md5)){ antivirus.setAntivirus(true); antivirus.setDesc(a.getDesc()); mAntivirusListT.add(antivirus); }else{ antivirus.setAntivirus(false); } } String name=pif.applicationInfo.loadLabel(pm).toString(); antivirus.setName(name); try { Thread.sleep(50+new Random().nextInt(100)); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } progress++; pb_antivirus.setProgress(progress); Message msg=Message.obtain(); msg.obj=antivirus; msg.what=SCANING; mHandler.sendMessage(msg); } Message msg=Message.obtain(); msg.what=SCAN_FINISH; mHandler.sendMessage(msg); }; }.start(); }
  • 相关阅读:
    BZOJ3670: [Noi2014]动物园
    BZOJ4424: Cf19E Fairy
    BZOJ1257: [CQOI2007]余数之和
    BZOJ2438: [中山市选2011]杀人游戏
    SDOI2017第一轮
    BZOJ4820: [Sdoi2017]硬币游戏
    NOIP2016
    HDU1848 Fibonacci again and again(SG 函数)
    HDU1517 Multiply Game
    HDU1907 Jhon
  • 原文地址:https://www.cnblogs.com/zzl521/p/8849386.html
Copyright © 2011-2022 走看看