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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:59:43+00:00 2026-05-31T13:59:43+00:00

I have a loop where i am created multiple button instances and with each

  • 0

I have a loop where i am created multiple button instances and with each instance they have a TouchListener. However, i am having trouble figuring out how to manage when the different buttons have been touched. What i am trying to accomplish is that each button represents a textview and when i touch the button i want to add that particular textview associated with that instance of the button to an arraylist. However, when the same button is touched again, i want to remove it from the list..and add it back again if it is touched again. Oh yeah addToOrder currently is global and initialized to true.

Thoughts?

EDIT****per my comments below button is now an instance of a subclass of Button that I wrote so that i can easily keep up with each instance of the button. That solved the issue.

here is the code:

 button.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
        int action = event.getActionMasked();
        //Log.d("Touched Add To Order Button with id of ", button.getId() + ": " + button.getText().toString());
        TextView relativeTitleView;
        ViewGroup relativeGroup = (ViewGroup)v.getParent();
        relativeTitleView = (TextView) relativeGroup.getChildAt(0);
        //Log.d("Add To Order Button Touched", relativeTitleView.getText().toString());

           /*if(action ==MotionEvent.ACTION_DOWN){                          
            addToOrder = (addToOrder) ? true : false;
            if(addToOrder)
                dbAccess.addToOrder(relativeTitleView.getText().toString());
            else
                dbAccess.removeFromOrder(relativeTitleView.getText().toString());
            }
           else if(action == MotionEvent.ACTION_UP){
                addToOrder = !addToOrder;

            }*/

           if(action == MotionEvent.ACTION_DOWN){
              if(button.getTouchInfo()){
               dbAccess.addToOrder(relativeTitleView.getText().toString());
               button.setTouchInfo(false);
              }
              else {
                dbAccess.removeFromOrder(relativeTitleView.getText().toString());
                button.setTouchInfo(true);
              }
         }

            return false;
        }
    });
  • 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-31T13:59:44+00:00Added an answer on May 31, 2026 at 1:59 pm

    If this is the only way items are added/removed from dbAccess, you can just switch based on whether or not it’s already there.

    if(dbAccess.contains(relativeTitleView.getText().toString())
       dbAccess.removeFromOrder(relativeTitleView.getText().toString());
    else
       dbAccess.addToOrder(relativeTitleView.getText().toString());
    

    Edit: Assuming dbAccess has a contains(), can’t tell what type it is here.

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

Sidebar

Related Questions

I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
I have a for loop that creates multiple UIImageViews that I add to self.view
I have created some python code which creates an object in a loop, and
I have a loop that reads each line in a file using getline() :
I have a loop like this: for i=1:no %some calculations fid = fopen('c:\\out.txt','wt'); %write
I have a .txt file that I created with multiple lines. When I run
I have created a stored procedure to delete data from multiple tables. my work
I've created a Canvas class which has an Array of multiple instances of CanvasEntity
We have about 7-8 tables in our Android application each having about 8 columns
I have a recordset loop that creates a table, and every 9 items it

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.