安卓下 按钮监听重复开启线程

public void onClick(View arg0) {
				if(isRun)handler.removeCallbacks(thread);
				else{
					thread = new Thread(new Runnable() {

						@Override
						public void run() {

							String json = UrlHtmlUtil.getHtmlJsonByUrl(uri);

							Message m = handler.obtainMessage();
							Bundle bundle = new Bundle();
							bundle.putString("jsondata", json);
							m.setData(bundle);
							m.what = 0x11;
							handler.sendMessage(m);

						}

					});
				cityName = et.getText().toString();
				thread.start();
				//bt.setEnabled(false);
				}
<span style="font-size:24px;">定义一个Boolean变量isRun来判断线程是否已经开启。如开启则抛出线程。</span>

posted on 2015-03-22 17:42  木鱼哥  阅读(182)  评论(0编辑  收藏  举报

导航