四中更新uI方法代码示例
来源:互联网 发布:素数判断c语言程序 编辑:程序博客网 时间:2024/06/05 13:32
package com.example.hanler;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
public class fourFORnewUI extends Activity {
private TextView tv1;
private TextView tv2;
private TextView tv3;
private TextView tv4;
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
tv4.setText("message");
};
};
public void forhandler()
{
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tv1.setText("OK");
}
});
}
public void runonuithread() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tv2.setText("runOnUiThread");
}
});
}
public void viewpost() {
tv3.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tv3.setText("viewpost");
String str=tv3.getText().toString();
}
});
}
public void sentmessage() {
mHandler.sendEmptyMessage(1);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newui);
tv1 = (TextView) findViewById(R.id.newui1);
tv2 = (TextView) findViewById(R.id.newui2);
tv3 = (TextView) findViewById(R.id.newui3);
tv4 = (TextView) findViewById(R.id.newui4);
new Thread() {
public void run() {
try {
Thread.sleep(2000);
viewpost();
forhandler();
runonuithread();
sentmessage();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
public class fourFORnewUI extends Activity {
private TextView tv1;
private TextView tv2;
private TextView tv3;
private TextView tv4;
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
tv4.setText("message");
};
};
public void forhandler()
{
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tv1.setText("OK");
}
});
}
public void runonuithread() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tv2.setText("runOnUiThread");
}
});
}
public void viewpost() {
tv3.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tv3.setText("viewpost");
String str=tv3.getText().toString();
}
});
}
public void sentmessage() {
mHandler.sendEmptyMessage(1);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newui);
tv1 = (TextView) findViewById(R.id.newui1);
tv2 = (TextView) findViewById(R.id.newui2);
tv3 = (TextView) findViewById(R.id.newui3);
tv4 = (TextView) findViewById(R.id.newui4);
new Thread() {
public void run() {
try {
Thread.sleep(2000);
viewpost();
forhandler();
runonuithread();
sentmessage();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}
阅读全文
0 0
- 四中更新uI方法代码示例
- Android:UI更新方法四:在Worker Thread中runOnUiThread直接刷新UI
- Android:UI更新方法四:在Worker Thread中runOnUiThread直接刷新UI
- android四种更新UI的方法
- Android更新UI的四种方法
- android ui 更新 示例
- android中更新UI线程方法
- viewDidAppear:方法中UI不更新
- Android中更新UI的方法
- android中更新UI的方法
- 多线程中更新UI万能方法
- Android中更新UI的方法
- android中接口实现更新UI方法
- Android更新UI的四种方法详解
- Android在非UI线程中更新UI的方法
- Android中更新UI的四种常用方式
- 应用更新示例代码
- 客户端更新示例代码
- 淘淘商城系列——nginx配置反向代理
- RepeatMasker安装和使用——基因组重复序列注释
- 在express中使用handlebars-helpers
- java 并发
- QT关于网络TCP通讯的记录(二)
- 四中更新uI方法代码示例
- sql中常用不常见函数部分总结
- 575. Distribute Candies
- java中使用反射机制获取实体类集合的某个属性值
- CC3200 学习
- 进程间通信 之 pipe(Linux)
- 冒泡排序
- 三步使用 JSON Server 模拟 API
- 微生物相关网络构建教程中文Microbial association network construction tutorial