手机震动、离开文本框自动查询归属地
1、用户输入为空时,进行查询,抖动手机 |
Vibrator.vibrate(new long[]{50,20,50,20},1); 参数1:先震动50ms,停止20ms,50ms,停止20ms,重复多次,震动50ms,停止20ms,震动50ms... 参数2:如果为-1,表示不重复,如果不为-1,那么就循环震动,注意震动时间和停止时间交替。 需要的权限:<uses-permission android:name="android.permission.VIBRATE"/> |
核心代码: // 手机震动
Vibrator vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
// vibrator.vibrate(5000);//震动5秒
long[] pattern = new long[] { 5000, 1000, 5000, 1000 };
vibrator.vibrate(pattern, 1);
// vibrator.cancel();//取消震动
|
2、离开文本框自动查询归属地 |
et_phone_number
.addTextChangedListener(
new
TextWatcher() {
@Override
public
void
onTextChanged(CharSequence s,
int
start,
int
before,
int
count) {
}
@Override
public
void
beforeTextChanged(CharSequence s,
int
start,
int
count,
int
after) {
}
// 文本变化后
@Override
public
void
afterTextChanged(Editable s) {
String phoneNum =
et_phone_number
.getText().toString().trim();
// 待查询手机号码
String address = null;
try
{
address = AddressDao.
getAddress
(NumberQueryActivity.
this
, phoneNum);
et_query_address
.setText(address);
}
catch
(IOException e) {
e.printStackTrace();
Toast.
makeText
(getApplicationContext(),
"查询手机号码地址失败!"
, Toast.
LENGTH_SHORT
).show();
}
}
});
|