LongClick listener in Android

In previous article we discussed the event listener with button for onClick. Now we are going to discuss LongClick . In android application we have facility to perform longclick event.

Example of longclick

We are taking the previous example for this event listener also.

		
		<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/t1" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_below="@+id/t1"
    android:layout_toRightOf="@+id/t1"
    android:layout_toEndOf="@+id/t1" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="ShowData"
    android:id="@+id/b1"
    android:layout_below="@+id/editText"
    android:layout_toRightOf="@+id/t1"
    android:layout_toEndOf="@+id/t1"
    android:layout_marginTop="62dp" />

		
		
		
		Button button = (Button)findViewById(R.id.b1);

button.setOnLongClickListener(

                new Button.OnLongClickListener() {


            public boolean onLongClick (View V){
                EditText e1 = (EditText) findViewById(R.id.editText);
                android.widget.TextView tv = (android.widget.TextView) findViewById(R.id.t1);
                tv.setText("long data "+e1.getText());
return true;

            }

        }


        );


		
		

Now execute the code and you will get following output.

event listener