这是一个倒数计时器,我想在几分钟和几秒钟内打印.ex(300000mili)5分钟,计数4:60,4:59 ......这是我的代码的一部分
final MyCounter timer = new MyCounter(300000,1000);
blue.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
timer.start();
}
});
}
public class MyCounter extends CountDownTimer {
public MyCounter(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
blue.setText("Live");
}
@Override
public void onTick(long millisUntilFinished) {
blue.setText((millisUntilFinished/60000)+":"+(millisUntilFinished/5000));
// i tried this
}
}
Run Code Online (Sandbox Code Playgroud)
如何在失踪20秒后振动?什么时候结束?谢谢,抱歉我的英语不好
使用handler想要定期运行计数为0,如果countis为1,否则请修复此代码.
mRunnable = new Runnable(){
@Override
public void run() {
if (count == 0) {
setImage();
count = 1;
} else {
weather = mContentResolver.getType(mUri);
setWeather(weather);
count = 0;
}
}
};
mHandler = new Handler();
mHandler.postDelayed(mRunnable, 3000);
Run Code Online (Sandbox Code Playgroud) 我在我的Android应用程序中有一个onClick事件触发以下代码,但它不断崩溃我的应用程序.我把它放在一个线程只是因为我读到那应该防止崩溃.此外,ctx指的是Activity的上下文(它是我在活动集中创建的变量等于此.我已阅读并尝试了几件事.任何帮助都会很棒.谢谢!
Thread toastThread = new Thread() {
public void run() {
Toast alertFailure = Toast.makeText(ctx, "Login Failed", Toast.LENGTH_LONG);
alertFailure.show();
}
};
toastThread.start();
Run Code Online (Sandbox Code Playgroud) 我需要每秒更新我的TextView.我用Timer和TimeTask写了它,但是每个人都说它被弃用的方法.有人可以告诉我如何制作简单的计时器,每1秒更新一次TextView,可能会从UI停止吗?
如果不再计算Handler的计数器怎么能停止?也许你可以告诉我如何处理下面的代码.
public void handler() {
nHandler.postDelayed(new Runnable() {
@Override
public void run() {
viewFlipper.setDisplayedChild(8);
}
}, 20000);
}
Run Code Online (Sandbox Code Playgroud) 我正在制作一个使用谷歌地图api v2的应用程序.我的问题是,当我注册摄像机更改监听器时,每当摄像机移动时,它就会在移动停止时执行.我想实现后者.如何修改我的代码才能在移动停止时注册?
这是我的代码:
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
ne = bounds.northeast;
sw = bounds.southwest;
ne1 = ne.latitude;
ne2 = ne.longitude;
sw1 = sw.latitude;
sw2 = sw.longitude;
new DownloadJSON().execute();
}
});
Run Code Online (Sandbox Code Playgroud) 我开始了ActivityB从ActivityA使用startActivity(intent),然后我开始CountDownTimer.现在暂停,我想结束ActivityB并ActivityA再次拥有前景.是否有可能阻止Activity另一个?
我有单独的地图类,其中我编写了与地图活动相关的所有逻辑,因为严格要求将两个地图相关的事物分开.现在从主应用程序活动我调用这样的函数:
Timer t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (mapObj.isLocationClientConnected)
Location currentLocation = mapObj.gotoCurrentLocation();
}
}, 0, refreshUserLocationInterval);
Run Code Online (Sandbox Code Playgroud)
在Map Class我有:
public Location gotoCurrentLocation() {
currentLocation = mLocationClient.getLastLocation();
LatLng ll = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
CameraUpdate cUpdate = CameraUpdateFactory.newLatLngZoom(ll, defaultZoom);
gMap.animateCamera(cUpdate);
return currentLocation;
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
06-22 19:56:30.900: E/AndroidRuntime(11413): FATAL EXCEPTION: Timer-0
06-22 19:56:30.900: E/AndroidRuntime(11413): java.lang.IllegalStateException: Not on the main thread
06-22 19:56:30.900: E/AndroidRuntime(11413): at kbh.b(Unknown Source)
06-22 19:56:30.900: E/AndroidRuntime(11413): at lzd.b(Unknown Source)
06-22 19:56:30.900: …Run Code Online (Sandbox Code Playgroud)