Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting

Distribute your Resume to 500+ Job Boards & Recruiters

7,142 questions

10,103 answers

573 users

How to add onLongClick event to Button in Android Java

1 Answer

0 votes
package com.example.avi.myapplication;

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 AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        Button myButton =(Button) findViewById(R.id.myButton);

        myButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                TextView myText = (TextView) findViewById(R.id.myText);
                myText.setText("android java");
        myButton.setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View v) {
                TextView myText = (TextView) findViewById(R.id.myText);
                myText.setText("long click");

                return true;


answered Mar 28, 2017 by avibootz