Android 用代理模式处理海量高频数据更新
2010-12-18 08:04:10 来源:WEB开发网cancel();
}
}
public void startTimer(){
refreshHandler.getHandler().postDelayed(this,DELAY_ONCE);
}
private void sendMsg(final int currColor){
final Runnable myUpdateResults = new Runnable() {
public void run() {
refreshHandler.updateBackground( id, currColor);
}
};
new Thread() {
public void run() {
refreshHandler.getHandler().post(myUpdateResults);
}
}.start();
}
public void stopTimer(){
this.cancel();
}
}
Java代码
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
public class TestActivity extends Activity implements RefreshHandlerInterface{
private Handler _messageHandler = new Handler();
@Override
public Handler getHandler() {
return _messageHandler;
}
@Override
public void updateBackground(Object handlerId, int color) {
if(!( handlerId instanceof CommonDefn.DoThingsReturn)) {
return; //invalid parameter
}
else {
TextView current = (TextView)(((CommonDefn.DoThingsReturn)handlerId).data);
if(current.getVisibility() != View.VISIBLE) {
return; //no need to update for the view
}
if(color<=0) {
current.setBackgroundDrawable(null);
current.setText(((CommonDefn.DoThingsReturn)handlerId).cmd.toString());
}
else {
current.setBackgroundColor( color);
}
current.postInvalidate();
}
}
/** Called when the activity is first created. */
点击下载:源码下载
赞助商链接