有时候更改字符串值

时间:2016-01-22 18:24:00

标签: android

我需要每次更改一些“字符串值”。有人可以告诉你怎么做吗?

我的意思是:AppStart>字符串值=“a”>在>之后30秒字符串值=“b”

2 个答案:

答案 0 :(得分:1)

您可以这样做以达到预期的效果:

private static final ScheduledExecutorService worker = 
Executors.newSingleThreadScheduledExecutor();

void someMethod() {
  Runnable task = new Runnable() {
    public void run() {
      /* Do something… */
    }
  };
  worker.schedule(task, 30, TimeUnit.SECONDS);
}

答案 1 :(得分:0)

您可以将任务发布到主线程以在特定时间后更新textview。请参阅以下代码:

public class HistoryActivity extends ActionBarActivity {
TextView mTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);

    String history = getIntent().getStringExtra("History");

    mTextView = (TextView)findViewById(R.id.txtHistory);
    mTextView .setText(history);

    Handler handler=new Handler();

    final Runnable runnable=new Runnable() {
        @Override
        public void run() {

            //put your textview update code here
            mTextView .setText(history);
            handler.postDelayed(this,30*1000);//reschedule this runnable
        }
    };

    handler.postDelayed(runnable,30*1000);

    }
}