1、直接NEW出Handler,然后通过发送消息的方式来调用:
mHandler.setMessage(Msg);
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case GlobalUtil.PROGRESS_DIALOG_SHOW:
progressDialog = GlobalUtil.createLoadingDialog(mContext, "正在加载,请稍后^_^");
progressDialog.show();
break;
case GlobalUtil.PROGRESS_DIALOG_DISMISS:
if (progressDialog != null) {
progressDialog.dismiss();
}
break;
}
}
};
2种方式:首先也是New一个Handler; 不过不在里面实现方法;而是重写Runable接口方法;在通过Post方法调用:如下代码
调用:handler.post(updateToBottom);
private Handler handler = new Handler();
private Runnable updateToBottom = new Runnable() {
@Override
public void run() {
int off = linear.getMeasuredHeight() - scrollview.getHeight();
if(off>0) {
scrollview.scrollTo(0, off);
}
}
};