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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:11:00+00:00 2026-06-01T05:11:00+00:00

I want to set up a separate listener to each switch in each of

  • 0

I want to set up a separate listener to each switch in each of my items in a listview. How do I go about accomplishing this ?

The method that is called in my asynchronous task is setQueues :

    private void setQueues(final JSONObject[] qInfo) 
{
    queues = new QueueItem[qInfo.length]; // QueueItem consists of a string(label) and a boolean(value)

    for(int i = 0; i < qInfo.length; i++)
    {
        queues[i] = new QueueItem();
        //final int ii = i;

        // Formatting the queue title
        String name = qInfo[i].optString("name").replace("-", " ");
        name = name.replace("_", " ");
        name = name.replace("ipinion", "");
        name = name.replace("  ", " ");
        name = capitalizeFirstLetters(name);
        queues[i].label = name;

        try {
            if(qInfo[i].getString("active").contains("1"))
            {
                Log.d("QBox", "Queue: Checkbox " + i + " : Checked TRUE");
                queues[i].value = true;
            }
            else
            {
                Log.d("QBox", "Queue Checkbox " + i + " : Checked FALSE");  
                queues[i].value = false;
            }
        } 
        catch (JSONException e) 
        {
            e.printStackTrace();
        }

    }

    lv.setAdapter(new QueueAdapter(getActivity(), 
            R.layout.queues_items, queues));
}

Any help is greatly appreciated. I feel like im missing something very obvious.

Edit : The getView method from QueueAdapter :

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    QueueHolder holder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new QueueHolder();
        holder.queueswitch = (Switch)row.findViewById(R.id.queues_item_switch);
        holder.txtLabel = (TextView)row.findViewById(R.id.queues_item_text);

        row.setTag(holder);
    }
    else
    {
    holder = (QueueHolder)row.getTag();
    }

    QueueItem queue = data[position];
    holder.txtLabel.setText(queue.label);
    holder.queueswitch.setChecked(queue.value);
    // Is this where you would set up your listener?    

    return row;
}
  • 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-01T05:11:02+00:00Added an answer on June 1, 2026 at 5:11 am
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        QueueHolder holder = null;
    
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new QueueHolder();
            holder.queueswitch = (Switch)row.findViewById(R.id.queues_item_switch);
            /* TRY PUTTING IT HERE */
            holder.txtLabel = (TextView)row.findViewById(R.id.queues_item_text);
    
            row.setTag(holder);
        }
        else
        {
        holder = (QueueHolder)row.getTag();
        }
    
        QueueItem queue = data[position];
        holder.txtLabel.setText(queue.label);
        holder.queueswitch.setChecked(queue.value);
        holder.queueswitch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //DO SOMETHING
            }
        });
    
        return row;
    }
    

    This way it would work! I am not sure but try putting it where “/* TRY PUTTING IT HERE */” stands, I’m not sure if it would work but it would be better since the initiating of the onClickListener only happens once…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have 16 bits I want to set to variables (2 separate bytes).
I want to separate a set of 3 numbers with a comma and set
Using EF-Code-First I want to set up a DB table that is related (1-1)
i have one textfield for input some serial number code.i want set this code
I want to set the delegate of an object inside a class method in
I have a coredata attribute called visitDate I want to set the date and
I want set interfaceOrientation in one UIView as LandscapeLeft and Portrait in other UIView.
i want set the visibility to itemized overlay in map view. if the zoom
I want set Listbox background to transparent but not working Is there any idea?
i want set class for repeater when doPostBack for those dataID i wan but

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.