为什么不重装()的WebView当您更改触摸的位置 [英] Why does not the reload() WebView when you change the position of touch
问题描述
晚上好!为什么不通过改变触摸位置刷新()。毕竟,code似乎是正确的。从code,我想你会明白我需要什么。 preferred是解决此问题的最简单的方法,我只是不明白的Java。
Good evening! Why does not Reload() by changing the touch position. After all, the code seems correct. From the code, I think you will understand what I need. Preferred is the easiest way to work around this problem, I just do not understand Java.
package com.example.pack.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends ActionBarActivity implements View.OnTouchListener {
float mX;
float mY;
float Start;
float Fin;
View rl;
WebView web;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.webView2);
web.loadUrl("http://example.com/page.html");
web.getSettings().setJavaScriptEnabled(true);
if (Start < Fin) {
new Timer().schedule(new TimerTask(){
@Override
public void run() {
// TODO Auto-generated method stub
web.reload();
}}, 1000, 1000);
}
rl = (View) findViewById(R.id.rl);
rl.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
mX = event.getX();
mY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Start = mY;
break;
case MotionEvent.ACTION_UP:
Fin = mY;
break;
}
return true;
}
}
在提前谢谢大家。
推荐答案
有几件事会错在这里。如果不指定默认值浮动它们默认为0.0,所以你的情况开始
和翅
都开始出0.0。在Android的的onCreate
是在创建您的活动时被调用,这意味着,当你启动应用程序,你只被调用一次。这意味着,当你的的onCreate
被称为启动和FIN都是0.0,所以开始&LT;鳍片
是假的,所以你永远不会创建计时器。
There are a few things going wrong here. When you don't assign default values to floats they default to 0.0, so in your case Start
and Fin
both start out at 0.0. In Android onCreate
is called when your Activity is created, which means that it only gets called once when you launch you app. That means when your onCreate
is called Start and Fin are both 0.0, so Start < Fin
is false so you never create the timer.
这篇关于为什么不重装()的WebView当您更改触摸的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!