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

  • Home
  • SEARCH
  • 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 6871505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:48:53+00:00 2026-05-27T03:48:53+00:00

Let me start by saying I am new to Android development but have a

  • 0

Let me start by saying I am new to Android development but have a strong background in C#, VB.

I have read a ton of posts on similar issues and tried the solutions but it never seems to work. I am certain it is something I am doing and it is based on my ignorance of the programming language.

So, I got some code for a ListAdapter to populate the Two Item List View.

import java.util.ArrayList;
...


public class ListAdapter extends BaseAdapter {

private Activity activity;
  private ArrayList<Integer> image;
  private ArrayList<String> list1;
  private ArrayList<String> list2;
  private static LayoutInflater inflater=null;

  public ListAdapter(Activity a, ArrayList<Integer> image, ArrayList<String> list1, ArrayList<String> list2) {
      this.activity = a;         
      this.image = image;
      this.list1 = list1;
      this.list2 = list2;
      ListAdapter.inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);      
  }

  public int getCount() {
    return image.size();        
  }

  public Object getItem(int position) {
      return position;
  }

  public long getItemId(int position) {
      return position;
  }

  public static class ViewHolder{
      public TextView text1;
      public TextView text2;
      public ImageView image;
  }

  public View getView(int position, View convertView, ViewGroup parent) {
      View vi=convertView;
      ViewHolder holder;
      if(convertView==null){

          vi = inflater.inflate(R.layout.grid_list_layout, null);

          holder=new ViewHolder();
          holder.text1=(TextView)vi.findViewById(R.id.item1);
          holder.text2=(TextView)vi.findViewById(R.id.item2);
          holder.image = (ImageView)vi.findViewById(R.id.icon);

          vi.setTag(holder);
      }
      else
          holder=(ViewHolder)vi.getTag();

          holder.text1.setText(this.list1.get(position));
          holder.text2.setText(this.list2.get(position));
          holder.image.setImageResource(this.image.get(position));

          return vi;
  }

}

I have modified the above to use ArrayList instead of Array in the original article. It works fine. What I want to do is detect the long click and prompt the user to delete or not.

The main.xml has this partial code which is the list view

<ListView
    android:id="@+id/lvResult"
    android:layout_width="fill_parent"
    android:layout_height="296dp"
    android:paddingLeft="10px"
    android:paddingRight="10px" >
</ListView>

There is another grid_list_layout.xml file which contains

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="72px"
    android:layout_height="wrap_content"
    android:layout_marginTop="5px" />

<TwoLineListItem
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/twolinelist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:onClick="onClick"
    android:orientation="vertical"
    android:paddingBottom="5px"
    android:paddingTop="5px" >

    <TextView
        android:id="@+id/item1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/item2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="30px"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</TwoLineListItem>

In the main activity it is instantiated(?) with

ListView lv = (ListView) findViewById(R.id.lvResult);
//listAdapter is declared further up
listAdapter = new ListAdapter(HomesterActivity.this, arrIcon, arrSSID, arrMAC);
    lv.setAdapter(listAdapter);

So, what I would like to know is how do I intercept a long click? Where do I put the various bits? i.e. there must be something in the XML file, but which one? I have tried

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onListItemClick(ListView l, View v, int position,long id)
        {
            //super.onListItemClick( l, v, position, id);
            Toast.makeText(this, position, Toast.LENGTH_LONG).show();
        }
    }

and various versions, but nothing seems to please the compiler!

If you have time and feel so inclined I would appreciate some education so I can get my mind around it.

  • 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-05-27T03:48:53+00:00Added an answer on May 27, 2026 at 3:48 am

    To get long clicks, you use setOnItemLongClickListener instead. Like this:

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View v, int position,long id)
        {
          //do stuff in here.
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start off by saying Im VERY new to iphone development, but Im
Let me start out by saying that I am new to Java/JSP web development,
Let me start by saying, I am new to Java programming. I have coded
Let me start off by saying, I'm not new to programming but am very
Let me start off by saying I'm brand new to Android programming. I'm using
First off, let me start by saying that I am totally new to working
Let me start by saying that I do not advocate this approach, but I
Let me start by saying I am new to programming. I am hoping to
Let me start by saying I'm pretty new to using interfaces. I'm writing a
Let me start off by saying that I am completely new with WPF (this

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.