0

下载的时候点暂停,没反应。不知道具体怎么描述,其实就是停的意思,但是实在想不出来。编码

public void onClick(View v) {

                      [color=#FF0000]if (flag == 0){//click mark[/color]

不能显示,红色只是一个标记。代码如下

holder.btns .setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View v) {

                  [color=#FF0000]if (flag == 0){//judge the click mark[/color] 

                    holder.ratingBarScore.setVisibility(View.GONE);
                    holder.pro.setVisibility(View.VISIBLE);
                    holder.textView.setVisibility(View.VISIBLE);
                    if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
                    }else {
//                        Toast.makeText(this, "there is no SD card", 1000).show();
                        Log.v("wjp", "7889900");
                    }
                    final String downloadUrl =(String)v.getTag();
                    Thread thread = new Thread(){
                        int count = 0;
                        public void run(){
                          Log.v("ccf", "onClick");
                          try {
                              downLoadFile(context, downloadUrl, gameName, holder);    
                              openFile(context, new File("/sdcard/9twan/"+ gameName +".apk"));
                              if(!WebHelper.REGISTER_FLAG){
                                  Log.v("GamesInfoListAdapter", "WebHelper.REGISTER_FLAG == false");
                                  String imei, mac, mobile_number, model, brand;
                                  boolean flag;
                                  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                                  imei = tm.getDeviceId();
                                  if(imei == null){
                                      imei = "CUSTOM" + WebHelper.generateRandomIMEIString(15);
                                  }
                                  mac = null;
//                                  mac = tm.getDeviceId(); 
                                  if(mac == null){
                                      mac = "CUSTOM" + WebHelper.generateRandomMacString(17);
                                  }
                                  mobile_number = tm.getLine1Number();
                                  model = tm.getLine1Number();
                                  brand = tm.getLine1Number();
                                  flag = WebHelper.regDevice(context, "install", imei, mac, mobile_number, model, brand);
                                  if(flag){
                                      WebHelper.REGISTER_FLAG = true;
                                      Log.v("GamesInfoListAdapter", "WebHelper.REGISTER_FLAG == true");
                                  }
                              }

                          }catch (Exception e){
                              e.printStackTrace();
                          }
                        }
                    };
                    Log.v("wjp", "running"+thread.getName());
                    thread.start();
                    Toast.makeText(context, "begin to download" + gameName, 0).show();
                    holder.btns.setBackgroundResource(R.drawable.tab_out);

                    [color=#FF0000]flag =1;[/color]//here is need to pause,how to write?
                    }else {
                          if(Thread.currentThread() !=null){
                              Thread.interrupted();
//                              Thread = null;
                          }
//                        thread.
//                        Thread.interrupted();//pause return boolean
//                        Thread.sleep(3000);
//                          Thread.

                        holder.btns.setBackgroundResource(R.drawable.tab_install);
                        flag =0;

                    }
                }

            });
        }
        return convertView;
4

1 回答 1

0

您正在尝试中断当前线程,您应该中断已启动的线程。您是否也在更改标志的值。您似乎有多个名为 flag 的变量

if(thread !=null){
 thread.interrupt();      
}
于 2012-09-04T03:24:30.543 回答