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

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Teach Your Child To Read

Disclosure: My content contains affiliate links.

32,307 questions

42,482 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;
            }
        });
    }
}

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Mar 28, 2017 by avibootz

Related questions

1 answer 228 views
1 answer 186 views
1 answer 221 views
...