Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:01:45+00:00 2026-06-04T22:01:45+00:00

what is wrong with this code? i try to add a long click listener

  • 0

what is wrong with this code?
i try to add a long click listener to an listview, but can’t get it right for some reason:

package ch.futurecom.adaptertest;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class AdapterTestActivity extends ListActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        ListView lv = getListView();

        lv.setLongClickable(true);
        lv.setOnLongClickListener(new OnLongClickListener()
        {
            @Override
            public boolean onLongClick(View v)
            {
                Toast.makeText(AdapterTestActivity.this, "long clicked", Toast.LENGTH_SHORT).show();
                return true;    
            }
        });

        lv.setAdapter(new ArrayAdapter<String>(this,R.layout.row,getResources().getStringArray(R.array.items)));
    }
}

pastebin links:
AdapterTestActivity.java -> http://pastebin.com/Pw30EkEz
row.xml -> http://pastebin.com/6FajncHT

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:01:46+00:00Added an answer on June 4, 2026 at 10:01 pm

    try AdapterView.OnItemLongClickListener as

    ListView lv = getListView();
                lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){ 
                       @Override 
                       public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) 
                      { 
                           Toast.makeText(AdapterTestActivity .this, "LongClicked", Toast.LENGTH_LONG).show();
                      } 
                 }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to add admob, but I have some problem with it. This is
Why is this code correct: try { } catch(ArrayOutOfBoundsException e) {} and this wrong:
What's wrong with this code? I get: TypeError: older is undefined (10 out of
Something must be wrong with this code right here: + (UIImage*)captureView:(UIView *)theView { UIGraphicsBeginImageContext(theView.frame.size);
I get an exception on the List.Add line when trying to run this code:
I am trying to add data to a database, in grails but get this
I must do something wrong, but dont know what.. I try to add a
Whats wrong with this code or what might be causing this problem? It's not
Whats wrong with this code? -(void) drawRect:(CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); if
what's wrong with this code ? i am a beginner <link type=text/css href=/css/custom-theme/jquery-ui-1.8.20.custom.css rel=stylesheet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.