Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,852 questions

51,773 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 {

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

        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
...