Twitter Facebook Delicious Digg Stumbleupon Favorites More

Saturday, 17 September 2016

GESTURE DETECTOR ANDROE

package com.httptesting.boston_two;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.GestureDetector;
import android.support.v4.view.GestureDetectorCompat;
import android.widget.TextView;

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

    private TextView tv;
    private GestureDetectorCompat gestureDetector;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv=(TextView)findViewById(R.id.textViraj);
        this.gestureDetector=new GestureDetectorCompat(this,this);
        gestureDetector.setOnDoubleTapListener(this);
    }

    @Override    public boolean onTouchEvent(MotionEvent event) {
        this.gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

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

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

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

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

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

    }

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

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

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

    }

    @Override    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        tv.setText("onFling");
        return true;
    }
}
-=======================================================================
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.httptesting.boston_two.MainActivity">

    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textAppearance="?android:attr/textAppearanceLarge"        android:text="@string/msg"        android:id="@+id/textViraj"        android:layout_centerVertical="true"        android:layout_centerHorizontal="true" />
</RelativeLayout>
Share:

EVENT HANDLING ANDROID

EVENT HANDLING ANDROID
MAIN ACTIVITY.JAVA
package com.httptesting.boston_one;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b=(Button)findViewById(R.id.buttonViraj);
        b.setOnClickListener(
               new  Button.OnClickListener()
               {
                   public void onClick(View v)
                   {
                       TextView tv=(TextView)findViewById(R.id.textViraj);
                       tv.setText("it work");
                   }
               }

                );
        b.setOnLongClickListener(
                new Button.OnLongClickListener()
                {
                    public boolean onLongClick(View v)
                    {
                        TextView tv=(TextView)findViewById(R.id.textViraj);
                        tv.setText("on long click");
                        return true;
                    }
                }

        );
    }
}
=======================================================================================
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.httptesting.boston_one.MainActivity">

    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textAppearance="?android:attr/textAppearanceLarge"        android:text="@string/viraj"        android:id="@+id/textViraj"        android:layout_alignParentTop="true"        android:layout_centerHorizontal="true"        android:layout_marginTop="72dp" />

    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/submit"        android:id="@+id/buttonViraj"        android:layout_centerVertical="true"        android:layout_centerHorizontal="true"        android:onClick="onclick"/>
</RelativeLayout>
Share:

ANDROID EVENT HANDLING TEXT CHANGE WITH TOST ON BUTTON CLICK

ANDROID EVENT HANDLING TEXT CHANGE WITH TOST ON BUTTON CLICK
MAIN ACTIVITY.JAVA
package com.httptesting.testing;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

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

        Button bone=(Button)findViewById(R.id.buttonOne);
        Button btwo=(Button)findViewById(R.id.buttonTwo);


        bone.setOnClickListener(
                new  Button.OnClickListener()
                {
                    public void onClick(View view)
                    {
                        TextView tv=(TextView)findViewById(R.id.textViewOne);
                        tv.setText("first");
                        Toast.makeText(getApplicationContext(),"first button", Toast.LENGTH_SHORT).show();
                    }
                }
        );
        btwo.setOnClickListener(
                new  Button.OnClickListener()
                {
                    public void onClick(View v)
                    {

                        TextView tv=(TextView)findViewById(R.id.textViewOne);
                        tv.setText("second");
                        Toast.makeText(getApplicationContext(),"second", Toast.LENGTH_SHORT).show();
                    }
                }

        );

    };
}

,XML FILE

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.httptesting.testing.MainActivity">

    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textAppearance="?android:attr/textAppearanceLarge"        android:text="Text Display Here"        android:id="@+id/textViewOne"        android:layout_alignParentTop="true"        android:layout_centerHorizontal="true"        android:layout_marginTop="47dp" />

    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/button_one"        android:id="@+id/buttonOne"        android:layout_below="@+id/textViewOne"        android:layout_alignParentLeft="true"        android:layout_alignParentStart="true"        android:layout_marginLeft="32dp"        android:layout_marginStart="32dp"        android:layout_marginTop="48dp"        android:onClick="bone" />

    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/button_two"        android:id="@+id/buttonTwo"        android:layout_alignBottom="@+id/buttonOne"        android:layout_alignParentRight="true"        android:layout_alignParentEnd="true"        android:onClick="btwo" />
</RelativeLayout>

Share:

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab