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>