如何将用户字符串

如何将用户字符串

如何将用户字符串放入Handler timer.postDelayed?

 public class Quotes extends Activity implements OnClickListener {

 ProgressDialog dialog;
 private WebView webview;
 Handler timer;
 Runnable runner;

 @Override
 public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      WebView adsview = (WebView) findViewById(R.id.ads);
      adsview.getSettings().setJavaScriptEnabled(true);
      adsview.loadUrl("http://www.dgdevelco.com/quotes/androidad.html");

      SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

      String q = SP.getString("appViewType","http://www.google.com");
      String c = SP.getString("appRefreshRate","20000");

      webview = (WebView) findViewById(R.id.scroll);
      webview.getSettings().setJavaScriptEnabled(true);
      webview.setWebViewClient(new QuotesWebView(this));
      webview.loadUrl(q);

      runner = new Runnable() {
      @Override
      public void run() {
           timer.postDelayed(runner, 2000000);
           webview.reload();
      }
      };
      timer = new Handler();
      timer.postDelayed(runner, 10000);

      findViewById(R.id.refresh).setOnClickListener(this);

 }

 @Override
 public void onPause(){
  super.onPause();
  try {
      timer.removeCallbacks(runner);
  } catch (Exception ex) {
      Log.e("MY APP ERROR", ex.getMessage());
  }
 }

 @Override
 public void onStop(){
  super.onStop();
  try {
      timer.removeCallbacks(runner);
  } catch (Exception ex) {
      Log.e("MY APP ERROR", ex.getMessage());
  }
 }

 public void onClick(View v){
      switch(v.getId()){
       case R.id.refresh:
      webview.reload();
       break;
     }
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu, menu);

      MenuItem about = menu.getItem(0);
      about.setIntent(new Intent(this, About.class));

      MenuItem preferences = menu.getItem(1);
      preferences.setIntent(new Intent(this, Preferences.class));

      return true;

      }
  }

最佳答案

像这样?

final String c = SP.getString("appRefreshRate","20000");

runner = new Runnable() {
      @Override
      public void run() {
           timer.postDelayed(runner, Long.valueOf(c));
           webview.reload();
      }

10-07 12:51