我正在使用计时器来制作秒表.计时器通过增加整数值来工作.我想通过不断更新textview在活动中显示此值.
这是我尝试更新活动的textview服务的代码:
protected static void startTimer() {
isTimerRunning = true;
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
elapsedTime += 1; //increase every sec
StopWatch.time.setText(formatIntoHHMMSS(elapsedTime)); //this is the textview
}
}, 0, 1000);
}
Run Code Online (Sandbox Code Playgroud)
关于在错误的线程中更新UI,我遇到了一些错误.
如何调整我的代码来完成不断更新textview的任务?
我想做以下事情,并且有几天坚持这些:
当我移动地图时,我试图绘制多段线(我已编码折线,但设法解码那些).
我发现的唯一解决方案是将Geopoints转换为屏幕坐标...如果我移动地图则不会移动.
我曾经HelloItemizedOverlay
添加了大约150个标记,它变得非常慢.
知道该怎么办?我在考虑线程(处理程序).
我正在寻找某种定时器功能,它定期执行一个给定的功能,比如每1分钟左右.
我也在寻找从所有标记/线等清除谷歌地图的方法.
我需要在一段时间后从当前活动开始活动.我编码如下.
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
new Timer().schedule(new TimerTask(){
public void run() {
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
}
}, 2000);
}
Run Code Online (Sandbox Code Playgroud)
但它不工作..继续崩溃..我的方法是否正确?我的清单文件如下
`
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FirstActivity"
android:label="@string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/title_activity_second" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.first.FirstActivity" />
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
怎么能在android中完成?
public final Timer timer = new Timer(10, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Do task here
}
});
Run Code Online (Sandbox Code Playgroud)
我需要能够调用timer.start(); 来自计时器所在的活动.
因此,在我的游戏中,有一个计分选项卡将在游戏结束时显示
这是我的标签得分示例
这是代码:
highscoretext = (TextView)findViewById(R.id.bt);
highscoretext.setText("0");
currentscore = (TextView)findViewById(R.id.ct);
currentscore.setText(String.valueOf(gamescore));
Run Code Online (Sandbox Code Playgroud)
这就是我保存将在最佳成绩中显示的分数的方式
SharedPreferences pref = getSharedPreferences("SavedGame", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("totalScore", gamescore);
if (gamescore > highscore){
highscoretext.setText(String.valueOf(gamescore));
editor.putInt("highscore", gamescore);
editor.commit();
Run Code Online (Sandbox Code Playgroud)
我不知道做一个动画来我TextView
喜欢这个
因此,当显示标签分数时,分数将从0计入游戏中获得的当前分数,例如:10
并且当分数停止计数时,如果分数>最佳分数,则最佳分数的值会更改
谁能帮我?
我正在 android 中开发新的应用程序。我需要从我当前的应用程序启动一个录音应用程序,我已经通过调用意图来启动它
MediaStore.Audio.Media.RECORD_SOUND_ACTION
Run Code Online (Sandbox Code Playgroud)
但现在我需要控制正在录制的媒体。我只需要记录 30 秒。当达到 30 秒时应停止记录。
有什么建议??
我有一个按钮,我想第一次将定时器设置为5秒,它应该在完成5秒后完成一些任务.此外,如果用户单击按钮2次,它应该启动计时器10秒,10秒后它应该执行特定的任务.如果用户点击第三次,它应该停止所有运行的计时器.所以我不知道如何实现计时器一次我搜索的是这个.但是在这个链接中它会在特定的时间段后不断重复,而我想要运行一次.
现在我想要什么
所以请告诉我如何执行此任何代码和源代码将不胜感激.