我是Android开发的新手.试图完成一些相当简单的事情 - 当计时器滴答时改变一些显示的文本.这是可能相关的代码:
CountDownTimer currentTimer;
Resources res;
TextView timerText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exercise);
res = getResources();
timerText = (TextView) findViewById(R.id.timer_text);
}
@Override
protected void onStart() {
super.onStart();
//"Get ready" countdown
currentTimer = new CountDownTimer(5000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
timerText.setText("" + (int)Math.ceil(millisUntilFinished / 1000.0));
}
@Override
public void onFinish() {
...
}
};
currentTimer.start();
}
Run Code Online (Sandbox Code Playgroud)
这在模拟的4.2.2设备上工作正常,但在4.1.2设备(物理和模拟)上,更改的TextView在倒计时进行时显示:

如果你不知道,这是数字5,4,3重叠.因此,当我为TextView设置新字符串时,会显示新字符串,但不会替换旧字符串.我的应用程序中使用的任何其他TextView都以相同的方式运行.
任何想法是什么问题以及如何解决它?
编辑:从XML布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ExerciseActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:orientation="vertical" >
...
<TextView
android:id="@+id/timer_text" …Run Code Online (Sandbox Code Playgroud) 我对Objective-C很新.我已经阅读了类似的问题,但我无法弄清楚如何用这些信息解决我的问题.
基本上,我这样做:
NSMutableArray* array1 = [[NSMutableArray alloc] initWithCapacity: 1];
NSNumber *n1 = [NSNumber numberWithInt: 12];
[array1 addObject: n1];
NSMutableArray* array2 = [[NSMutableArray alloc] initWithCapacity: 1];
NSNumber *n2 = [NSNumber numberWithInt: 13];
[array2 addObject: n2];
Run Code Online (Sandbox Code Playgroud)
将NSNumber 12添加到数组中可以很好地完成,但是添加13(或更高的值)不会; 程序在运行时崩溃(没有错误消息,并且生成的stackdump文件完全空白).如果重要的话,我正在Cygwin中使用gcc进行编译.我知道这可能与保留计数有关,就像我上面提到的问题一样,但我不知道如何修复它.即使我注释掉最后一行,它也会崩溃......所以它会在numberWithInt调用时崩溃,这意味着如果我为n2添加一个retain语句,它就没有机会被调用了.
编辑:因为我被要求提供更多代码,这里是我为了测试这个问题而制作的文件:
#import <stdio.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSValue.h>
int main( int argc, const char *argv[] )
{
printf("1.\n");
NSMutableArray* array1 = [[NSMutableArray alloc] initWithCapacity: 1];
NSNumber *n1 = [NSNumber numberWithInt: 12];
[array1 addObject: n1];
NSMutableArray* array2 = [[NSMutableArray alloc] initWithCapacity: 1];
NSNumber …Run Code Online (Sandbox Code Playgroud)