gpt4 book ai didi

java - 如何将用户字符串拉入timer.postDelayed

转载 作者:行者123 更新时间:2023-12-01 05:43:11 26 4
gpt4 key购买 nike

如何将用户字符串拉入处理程序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();
}

关于java - 如何将用户字符串拉入timer.postDelayed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6616362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com