1.定义Handler:
Handler onlineHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.arg1) { case 0: { home_0.setImageResource(R.drawable.home_2_style); break; } case 1: { home_0.setImageResource(R.drawable.home_2_status_style); break; } } home_0.postInvalidate(); } };
2,定义Runnable:
Runnable onlineRunnable = new Runnable() { @Override public void run() { Message m = new Message(); if (readRd() != null && readRd().trim().equals("0")) { m.arg1 = 0; } else { m.arg1 = 1; } onlineHandler.sendMessage(m); //每隔5秒执行一次 onlineHandler.postDelayed(onlineRunnable, 5000); }
3.启动线程:
onlineHandler.post(onlineRunnable);
要实现activity的跳转,除了创建一个activity类外,必须在
AndroidManifest.xml文件里做声明。例如
<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ApiDemos" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".EditorFrame"/>
其中ApiDemos和EditorFrame是创建的activity对象
Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("txt2tags", txt2tags); intent .setClass(EditorFrame.this, ApiDemos.class);//EditorFrame 为当前界面的Activity,ApiDemos为要跳转的类 intent.putExtras(bundle); startActivity(intent);
之中bundle是用于activity之间传递参数
获得activity之间的参数
Bundle bundle=this.getIntent().getExtras(); strfromEditor=bundle.getString("txt2tags");
Activity的详细解析可以看
http://www.360doc.com/content/12/0410/13/7656232_202461086.shtml#
和
http://www.ibm.com/developerworks/cn/opensource/os-cn-android-actvt/
<!--EndFragment--><result name="dayExcel" type="stream"> <param name="contentType">application/vnd.ms-excel</param> <param name="contentDisposition">filename="export.xls"</param> <param name="bufferSize">1024</param> </result>
InputStream is; public String execute() { Label label; WritableWorkbook workbook; ByteArrayOutputStream os = new ByteArrayOutputStream(); try { workbook = Workbook.createWorkbook(os); WritableSheet sheet = workbook.createSheet("Sheet1", 0); label = new jxl.write.Label(0, 0, "Time/Hour"); sheet.addCell(label); for (int i = 0; i < 24; i++) { if (i < 10) { label = new jxl.write.Label(0, i+1, "0" + i); sheet.addCell(label); } else { label = new jxl.write.Label(0, i+1, String.valueOf(i)); sheet.addCell(label); } } workbook.write(); workbook.close(); } catch (Exception e) { e.printStackTrace(); } is = new ByteArrayInputStream(os.toByteArray()); return "excel"; } public InputStream getIs() { return is; } public void setIs(InputStream is) { this.is = is; } public InputStream getInputStream() throws Exception { return is; }