Home Work from Ep.22

+2 Жељко Симић · December 24, 2014
This is my work.


http://i.imgur.com/Iv4XtFN.png



public class MainActivity extends ActionBarActivity implements GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener{

    private TextView mojText;
    private GestureDetector gestureDetector;

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

        FrameLayout Strana = (FrameLayout)findViewById(R.id.Strana);

        mojText = (TextView)findViewById(R.id.mojText);
        Button bt1 = (Button)findViewById(R.id.bt1);

        bt1.setOnClickListener(
                new Button.OnClickListener(){
                    public void onClick(View v){
                        mojText.setText("I just got taped!");
                    }
                }
        );

        gestureDetector = new GestureDetector(this,this);
        gestureDetector.setOnDoubleTapListener(this);

        Strana.setOnTouchListener(new FrameLayout.OnTouchListener(){
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                gestureDetector.onTouchEvent(event);
                return true;
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
////////////////////////Pocetak pomeraja

    @Override
   public boolean onDown(MotionEvent e) {
        mojText.setText("onDown");
        return true;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        mojText.setText("onShowPress");
    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        mojText.setText("onSingleTapUp");
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        mojText.setText("onScroll");
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        mojText.setText("onLongPress");
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        mojText.setText("onFling");
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        mojText.setText("onSingleTapConfirmed");
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        mojText.setText("onDoubleTap");
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        mojText.setText("onDoubleTapEvent");
        return false;
    }
////// Kraj pomeraja

}


Post a Reply

Replies

Oldest  Newest  Rating
0 Milan Obrenovic · December 30, 2014
Yes that's the same I am wondering too. All methods must be implemented in order for Gesture to work. Bucky haven't mentioned this, so can you explain this to us, Bucky? Do all of them have to be implemented in order for it to work and why?
0 Жељко Симић · December 30, 2014
Gesture listener must have all implemented methods or it will show error idk why. :P
0 Sourabh Kumar · December 26, 2014
In override method section why is it not possible to just use the onScroll and on Fling method.
Everytime I use just those two methods, It shows me an error. Why do I have to use all methods ??
0 Milan Obrenovic · December 26, 2014
Ahhh, I have been putting

bt1.setOnClickListener(
   new Button.OnClickListener(){
       public void onClick(View v){
           mojText.setText("I just got taped!");
       }
   }
);

In onDown method instead of onCreate. Oh well, at least I know what dumb mistake i've made. And also, FrameLayout isn't necessary.

Svaka cast brate  :)
0 Жељко Симић · December 25, 2014
Thanks, Bucky! :D
+1 Bucky Roberts · December 24, 2014
Nice!  :)
  • 1

Java / Android Development

107,178 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator