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 7968357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:03:49+00:00 2026-06-04T07:03:49+00:00

I’m trying to register a long click on my listView row so it will

  • 0

I’m trying to register a long click on my listView row so it will then display an Invisible button.
Problem is that when I long press the row, the button appears correctly but only it appears in 2 different rows. I

Can you please look at my code and tell me why it set my button visible in 2 rows instead of just the one I clicked on?

here my adapter class:

package android.GUI;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

// This is a custom adapter that will use cursor to get data from SQLite DB as the source.

public class FastScrollAdapter extends CursorAdapter {

    private LayoutInflater mInflater;
    private Cursor cursor;

    public FastScrollAdapter(Context context, Cursor c) {
        super(context, c);
        this.mInflater = LayoutInflater.from(context);
        this.cursor = c;

    }

    public FastScrollAdapter(Context context, Cursor c, boolean autoRequery) {
        super(context, c, autoRequery);
        this.mInflater = LayoutInflater.from(context);
        this.cursor = c;
    }

    // Here we shall look to see if the View already exists and create a new one
    // if not.

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;

        // If view doesn't exists = create a new one and also store it (all of
        // the views) in our ViewHolder class called "holder"
        if (convertView == null) {

            convertView = this.mInflater.inflate(R.layout.list_entry, null);

            holder = new ViewHolder();

            holder.LL = (LinearLayout) convertView.findViewById(R.id.layoutBG);
            holder.delete = (Button) convertView.findViewById(R.id.deleteItem);
            holder.LL.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    // TODO Auto-generated method stub
                    holder.delete.setVisibility(View.VISIBLE);
                    return false;
                }
            });

            holder.rowID = (TextView) convertView.findViewById(R.id.rawId);
            holder.info = (TextView) convertView.findViewById(R.id.Info);
            holder.info.setTypeface(Entry.roboto);
            holder.info.setText("Info");
            holder.dateDisp = (TextView) convertView
                    .findViewById(R.id.dateDisp);
            holder.day = (TextView) convertView.findViewById(R.id.day);
            holder.finish = (TextView) convertView.findViewById(R.id.finish);
            holder.hourMin = (TextView) convertView.findViewById(R.id.hourMin);
            holder.shiftDisp = (TextView) convertView
                    .findViewById(R.id.shiftDisp);
            holder.start = (TextView) convertView.findViewById(R.id.start);
            holder.timestarted = (TextView) convertView
                    .findViewById(R.id.timestarted);

            convertView.setTag(holder);

            // If exists, just fetch this view and display it.
        } else {
            holder = (ViewHolder) convertView.getTag();

        }
        this.cursor.moveToPosition(position);

        // Set some values...
        /*************** Taken From DB ******************/
        holder.start.setText(this.cursor.getString(this.cursor
                .getColumnIndex(DBAdapter.KEY_START)));
        holder.start.setTypeface(Shifts.roboto);

        holder.shiftDisp.setText(this.cursor.getString(this.cursor
                .getColumnIndex(DBAdapter.KEY_HOURS)));
        holder.shiftDisp.setTypeface(Shifts.roboto);

        holder.rowID.setText(this.cursor.getString(this.cursor
                .getColumnIndex(DBAdapter.KEY_ROWID)));
        holder.rowID.setTypeface(Shifts.roboto);

        holder.dateDisp.setText(this.cursor.getString(this.cursor
                .getColumnIndex(DBAdapter.KEY_DATE)));
        holder.dateDisp.setTypeface(Shifts.roboto);

        holder.day.setText(this.cursor.getString(this.cursor
                .getColumnIndex(DBAdapter.KEY_DAY)));
        holder.day.setTypeface(Shifts.roboto);

        holder.finish.setText(this.cursor.getString(this.cursor
                .getColumnIndex(DBAdapter.KEY_END)));
        holder.finish.setTypeface(Shifts.roboto);

        /*************** Regular ones ******************/

        holder.info.setTypeface(Shifts.roboto);
        holder.info.setText("Info:");

        holder.hourMin.setTypeface(Shifts.roboto);
        holder.hourMin.setText("Shift:");

        holder.timestarted.setTypeface(Shifts.roboto);
        holder.timestarted.setText("Duration:");

        return convertView;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {

        return null;
    }

    static class ViewHolder {

        TextView rowID;
        TextView info;
        TextView dateDisp;
        TextView day;
        TextView timestarted;
        TextView start;
        TextView finish;
        TextView hourMin;
        TextView shiftDisp;
        Button delete;
        LinearLayout LL;

    }

}
  • 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-04T07:03:50+00:00Added an answer on June 4, 2026 at 7:03 am

    The issue is due to view recycling. To maintain the state of your button view you need to maintain a separate array of their state. I do it like this:

    In your adapter add an array:

    public static int[] buttonState;
    

    In your constructor add a method:

    populateButtonState();
    

    The method (0 will mean not visible, 1 will be visible):

    public static void populateButtonState() {
        buttonState = new int[c.getCount()];
        int i = 0;
        while (c.isAfterLast() == false) {
            buttonState[i] = 0;
            i++;
            c.moveToNext();
        }
    }
    

    Then in your getView, you set the visibility based on the array:

    holder.delete = (Button) convertView.findViewById(R.id.deleteItem);           
    if(buttonState[position] = 1) holder.delete.setVisibility(View.VISIBLE);                
    

    You also need to add to your onLongClick (assuming you want onLongClick to toggle the status):

    if(buttonState[position] = 1) {
        holder.delete.setVisibility(View.INVISIBLE);
        buttonState[position] = 0;
    } else {
        holder.delete.setVisibility(View.VISIBLE);
        buttonState[position] = 1;
    }                           
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.