1

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;
    }
}

In advance thank you all.

Nick Nick
  • 71
  • 6

1 Answers1

0

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.

CaseyB
  • 24,780
  • 14
  • 77
  • 112
  • Put the if containing the timer code under where you set Start and Fin – CaseyB Mar 03 '16 at 18:35
  • No. I'm not going to "write full code." We're here to help, not do it for you. – CaseyB Mar 03 '16 at 19:21
  • You do not do anything for me. Are you ready to write working code. If I myself could solve the problem, I would not write here. I thought 3 hours to change something but in the shuffle. I want to understand how the whole mechanism. If you write code, I can more or less figure out what's what. And thus (provessionalnymi tips) I do not get it. Thank you. – Nick Nick Mar 03 '16 at 19:33