Android 让你的SeekBar 也支持长按事件
2010-09-06 08:38:00 来源:WEB开发网// TODO Auto-generated method stub
do {
i++;
try {
Thread.sleep(400);
Message msg = hand.obtainMessage();
msg.arg1 = i;
msg.sendToTarget();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} while (isStop);
}
};
}
/**
* 获取一个handler 对象
* @param 0代表onTouch 1代表onChange
* @param 视图对象
* @param 进度
* @return 返回一个handler对象
*/
public Handler getHandler(final int j, final View v, final int progress) {
Handler h = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
switch (j) {
case 0:
if (msg.arg1 == 3) {
if (longClick != null) {
longClick.onLongClick(v);
}
}
break;
case 1:
if (msg.arg1 == 1) {
pp = progress;
}
if (msg.arg1 == 2) {
if (pp != progress) {
i = 0;
}
}
if (msg.arg1 == 3) {
i = 0;
if (pp == progress) {
if (longClick != null) {
longClick.onLongClick(seekBarDemo.this);
}
}
}
break;
}
super.handleMessage(msg);
}
};
return h;
}
/**
* 设置长按事件
* @param longClick
*/
public void setOnLongSeekBarClick(onLong longClick) {
this.longClick = longClick;
}
/**
* 设置进度改变事件
* @param change
*/
public void setOnSeekBarChange(onChange change) {
更多精彩
赞助商链接