我是android应用程序开发的初学者。我想做一个应用程序,是卡拉OK风格,不知怎的,我可以使图像变化在一个特定的间隔。然而,我在文字方面有一个问题,它不会随着歌曲的时间而改变。我只是使用文本视图,但我想实现TextSwitcher,但我真的不知道如何实现。我知道如何使用ViewFlipper,但是viewflipper只用于静态间隔。(我想?)请帮助我显示文本,并使它改变与其相应的时间?谢谢。另外,不使用数组也可以使用TextSwitcher吗?我认为,我需要展示的文本太多了,不可能出现在一个数组中。
到目前为止,我的情况如下:
public class LetItGo extends Activity
{
private ViewFlipper myviewflipper;
TextView t; private String sText;
private Handler mHandler = new Handler();
private Runnable mWaitRunnable = new Runnable() {
public void run() {
t.setText(sText);
}
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
myviewflipper = (ViewFlipper) findViewById(R.id.flipper1);
myviewflipper.setAutoStart(true);
myviewflipper.setFlipInterval(5000);
myviewflipper.startFlipping();
t=(TextView)findViewById(R.id.textView1);
sText = ("Let It Go / Let Her Go Mash Up" + "\n by Sam Tsui");
t.setText(sText);
//1
sText = ("Let it go, let it go");
mHandler.postDelayed(mWaitRunnable, 1000*10);
//2
sText = ("You only need the light when its burning low");
mHandler.postDelayed(mWaitRunnable, 6000*10*10);
//3
sText = ("Let it go, let it go");
mHandler.postDelayed(mWaitRunnable, 9000*10);
//4
sText = ("You only miss the sun when it starts to snow");
mHandler.postDelayed(mWaitRunnable, 13000*10);
//5
sText = ("And here I stand, \n and here I'll stay");
mHandler.postDelayed(mWaitRunnable, 17000*10);
//6
sText = ("You only know you love her when you let her go");
mHandler.postDelayed(mWaitRunnable, 19000*10);
//7
sText = "The cold never bothered me anyway";
mHandler.postDelayed(mWaitRunnable, 25000*10);
//8
sText = ("Staring at the bottom of your glass");
mHandler.postDelayed(mWaitRunnable, 34000*10);
//9
sText = ("Hoping one day you'll make a dream last ");
mHandler.postDelayed(mWaitRunnable, 37000*10);
//10
sText = ("But dreams come slow");
mHandler.postDelayed(mWaitRunnable, 4000*100);
//11
sText = ("and they go so fast");
mHandler.postDelayed(mWaitRunnable, 42000*10);
//12
sText = ("You see her when you close your eyes ");
mHandler.postDelayed(mWaitRunnable, 47000*10);
//13
sText = ("Maybe one day you'll understand why");
mHandler.postDelayed(mWaitRunnable, 5000*100);
//14
sText = "Everything you touch surely dies";
mHandler.postDelayed(mWaitRunnable, 54000*10);
//15
sText = ("Don’t let them in, don’t let them see ");
mHandler.postDelayed(mWaitRunnable, 62000*10);
//16
sText = ("Be the good guy you always have to be ");
mHandler.postDelayed(mWaitRunnable, 65000*10);
//17
sText = ("Conceal, don’t feel, don’t let them know ");
mHandler.postDelayed(mWaitRunnable, 69000*10);
//18
sText = ("Well, now they know");
mHandler.postDelayed(mWaitRunnable, 75000*10);
//19
sText = ("Let it go, let it go");
mHandler.postDelayed(mWaitRunnable, 78000*10);
//20
sText = ("You only need the light when its burning low");
mHandler.postDelayed(mWaitRunnable, 81000*10);
//21
sText = ("Let it go, let it go");
mHandler.postDelayed(mWaitRunnable, 85000*10);
//22
sText = ("You only miss the sun when it starts to snow");
mHandler.postDelayed(mWaitRunnable, 88000*10);
//23
sText = ("And here I stand, \n and here I'll stay");
mHandler.postDelayed(mWaitRunnable, 92000*10);
//24
sText = ("You only know you love her when you let her go");
mHandler.postDelayed(mWaitRunnable, 98000*10);
//25
sText = ("The cold never bothered me anyway");
mHandler.postDelayed(mWaitRunnable, 104000*10);
//26
sText = ("Let it go,");
mHandler.postDelayed(mWaitRunnable, 112000*10);
//27
sText = ("let her go");
mHandler.postDelayed(mWaitRunnable, 116000*10);
//28
sText = ("You only need the light when it's burning low");
mHandler.postDelayed(mWaitRunnable, 121000*10);
//29
sText = ("You only miss the sun when it starts to snow");
mHandler.postDelayed(mWaitRunnable, 124000*10);
//30
sText = ("You only know you love her when you let her go");
mHandler.postDelayed(mWaitRunnable, 127000*10);
//31
sText = ("You only know you've been high when you're feeling low");
mHandler.postDelayed(mWaitRunnable, 134000*10);
//32
sText = ("You only hate the road when you’re missin' home");
mHandler.postDelayed(mWaitRunnable, 138000*10);
//33
sText = ("You only know you love her when you let her go");
mHandler.postDelayed(mWaitRunnable, 141000*10);
//34
sText = ("And now you know ooooooh");
mHandler.postDelayed(mWaitRunnable, 146000*10);
//35
sText = ("Let it go, let it go");
mHandler.postDelayed(mWaitRunnable, 152000*10);
//36
sText = ("You only need the light when its burning low");
mHandler.postDelayed(mWaitRunnable, 155000*10);
//37
sText = ("Let it go, let it go");
mHandler.postDelayed(mWaitRunnable, 158000*10);
//38
sText = ("You only miss the sun when it starts to snow");
mHandler.postDelayed(mWaitRunnable, 162000*10);
//39
sText = ("And here I stand,");
mHandler.postDelayed(mWaitRunnable, 166000*10);
//40
sText = ("and here I'll stay");
mHandler.postDelayed(mWaitRunnable, 169000*10);
//41
sText = ("You only know you love her when you let her go" + " \n oooooohhhhh...");
mHandler.postDelayed(mWaitRunnable, 172000*10);
//42
sText = ("dudududu... ");
mHandler.postDelayed(mWaitRunnable, 181000*10);
//43
sText = ("The cold never bothered me anyway");
mHandler.postDelayed(mWaitRunnable, 192000*10);
//44
sText = ("Let It Go / Let Her Go Mash Up" + "\n by Sam Tsui");
mHandler.postDelayed(mWaitRunnable, 197000*10);
}
}我不知道我做得对不对。我只是根据我的研究把事情整合在一起。在这段代码中,显示了最后一个sText,并且没有改变。我不知道该怎么办了。谢谢你的帮助。:)
发布于 2014-02-19 19:48:38
当一个Handler在某个时刻运行时,它将使用sText的当前和最新内容。所有的处理程序都能很好地工作,但是他们都看到了sText =(“让它走/让她去捣毁”+ "\n由山姆崔克“)的内容,这是最后一个sText = ("sometext")调用;(第44次),因为sText =(”某某物“)命令都是在应用程序运行时的第一分钟执行的。
那该怎么办呢?
移除所有
sText = ("Some Text"); 除了第一首(歌曲的标题)。
将您的mWaitRunnable重写如下:
为要打印的行数声明一个整数:
int lineNumber = 1;
private Runnable mWaitRunnable = new Runnable() {
public void run() {
switch (lineNumber) {
case 1:
sText = ("Let it go, let it go");
break;
case 2:
sText = ("You only need the light when its burning low");
break;
case 3:
sText = ("Let it go, let it go");
break;
case 4:
sText = ("You only miss the sun when it starts to snow");
break;
// continue up to case 44:
default:
break;
}
t.setText(sText);
lineNumber++;
}
}; 享受:)
https://stackoverflow.com/questions/21888919
复制相似问题