我试图创建一个包含我输入的提示的textView。这些提示将存储在sting Array中,如下所示。如何让这个字符串数组中的项目在几秒钟后更改
</string-array>
<string-array >
<item> Use low energy compact fluorescent lamps as replacements for traditional incandescent lamps.</item>
<item >Ensure that thermostats for appliances are effective and set at moderate levels.</item>
<item >Install low-flow shower heads and faucet aerators to reduce water usage and its associated energy for heating></item>
</string-array>
答案 0 :(得分:0)
试试这段代码 -
final String[] tipsArray = getResources().getStringArray(R.array.tips);
final Handler tipsHanlder = new Handler();
Runnable tipsRunnable = new Runnable() {
@Override
public void run()
{
int tipPosition = 0;
//set number of tip(randon/another way)
tipsTextView.setText(tipsArray[tipPosition]);
tipsHanlder.postDelayed(this, 5000);
}
};
tipsHanlder.post(tipsRunnable);
您需要提供基于Randon Generator或其他方法的小费编号。
P.S为您的String数组提供XML中的名称。