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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:35:37+00:00 2026-06-15T19:35:37+00:00

I have a HorizontalScrollView in my android application and inside it I have 40

  • 0

I have a HorizontalScrollView in my android application and inside it I have 40 button, I want to implement a listener which retrieve data from database depending on the button clicked for example:

if the button number 1 was clicked, the listener should retrieve
data from database which related to week 1

do I have to implement a listener to each button or is there any way to know which button was clicked and use one listener to all the buttons with a change of the button number and week to retrieve ?

Database query method

DataBaseHelper myDbHelper = new DataBaseHelper(this);
        SQLiteDatabase db = myDbHelper.getReadableDatabase();

        String selectWebQuery = "select * from zweeks where zweeks_id = " + weekSince ;
        Cursor cursor = db.rawQuery(selectWebQuery, null);

        int CurrentDay=(int) (numberOfDaysSince%7);
        if(CurrentDay==0)CurrentDay=7;
        System.out.println("current Day="+CurrentDay);

        String     string1 =null;
        String     string2 = null;
        String     string3 = null;
        String     string4 = null;
        String     string5 = null;
        String     string6 = null;
        String     string7 = null;
        String tags=null;

        if (cursor != null)
                { cursor.moveToFirst();
                string1 = cursor.getString(1);
                string2 = cursor.getString(2);
                string3 = cursor.getString(3);
                string4 = cursor.getString(4);
                string5 = cursor.getString(5);
                string6 = cursor.getString(6);
                string7 = cursor.getString(7);

          String tags1 ="<head><style>body{float:right;text-align:right;word-wrap: break-word; }</style><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body>";

                switch(CurrentDay){

              case 1:tags=tags1+string1+"<img src=\"file:///android_res/drawable/dottedline.png\" />"+string2+"<br><br>"+string3+"<br><br>"+string4+"<br><br>"+string5+"<br><br>"+string6+"<br><br>"+string7+"<img src=\"file:///android_res/drawable/line.png\" /><br>" ;

              break;
              case 2:tags=tags1+string2+"<br><img src=\"file:///android_res/drawable/dottedline.png\" /><br>"+string3+"<br><br>"+string4+"<br><br>"+string5+"<br><br>"+string6+"<br><br>"+string7+"<br><img src=\"file:///android_res/drawable/line.png\" /><br>"+string1+"<br>" ;

              break;
              case 3:tags=tags1+string3+"<br><img src=\"file:///android_res/drawable/dottedline.png\" /><br>"+string4+"<br><br>"+string5+"<br><br>"+string6+"<br><br>"+string7+"<br><img src=\"file:///android_res/drawable/line.png\" /><br>"+string1+"<br><br>"+string2+"<br>" ;

              break;
              case 4:tags=tags1+string4+"<br><img src=\"file:///android_res/drawable/dottedline.png\" /><br>"+string5+"<br><br>"+string6+"<br><br>"+string7+"<br><img src=\"file:///android_res/drawable/line.png\" /><br>"+string1+"<br><br>"+string2+"<br><br>"+string3+"<br><br>" ;

              break;
              case 5:tags=tags1+string5+"<br><img src=\"file:///android_res/drawable/dottedline.png\" /><br>"+string6+"<br><br>"+string7+"<br><img src=\"file:///android_res/drawable/line.png\" /><br>"+string1+"<br><br>"+string2+"<br><br>"+string3+"<br><br>"+string4+"<br><br>" ;

              break;
              case 6:
                  tags=tags1+string6+"<br><img src=\"file:///android_res/drawable/dottedline.png\" /><br>"+string7+"<br><img src=\"file:///android_res/drawable/line.png\" /><br>"+string1+"<br><br>"+string2+"<br><br>"+string3+"<br><br>"+string4+"<br><br>"+string5+"<br><br>" ;

              break;
              case 7:
                  tags=tags1+string7+"<br><img src=\"file:///android_res/drawable/dottedline.png\" /><br>"+string1+"<br><br>"+string2+"<br><br>"+string3+"<br><br>"+string4+"<br><br>"+string5+"<br><br>"+string6+"<br><br>" ;

              break;

            }

          } 

      webView.loadDataWithBaseURL("file:///android_res/drawable/", tags, "text/html", "UTF-8", null);
}

this sentence should be dynamic depending on the button clicked

  • String selectWebQuery = “select * from zweeks where zweeks_id = ” +
    weekSince ;

Thanks in advance.

  • 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-15T19:35:38+00:00Added an answer on June 15, 2026 at 7:35 pm

    It is possible if you make your Activity implement onClickListener and then you can distinguish which button was clicked. An example of such approach:

    public class FirstActivity extends Activity implements OnClickListener {.....
    
    @Override
    public void onClick(View v) { // Parameter v stands for the view that was clicked.  
    
        // getId() returns this view's identifier.
        if(v.getId() == R.id.leftButton){
            // setText() sets the string value of the TextView
            changingTextView.setText("You clicked First");
        }else if(v.getId() == R.id.rightButton){
            changingTextView.setText("You clicked Second");
        }
    }
    

    You could make it even better by setting tags to your button and then using something like :

    int numberOfWeek=v.getTag();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a table which is basically done by HorizontalScrollView inside a ScrollView
I have a HorizontalScrollView that has lots of views and images inside it. The
HI! I have a surfaceView inside a horizontal scrollview that I want to fill
I have an ListView inside a HorizontalScrollView and it works perfectly fine, except for
I want to implement the concept of Slide to open concept in my application.
I have a HorizontalScrollView in Android that looks like the following in the xml.
i need to implement this layout in android..the view must be have two list
I have a custom Scrollview, HorizontalScrollview, and inside is a dynamic table. Each row
I have a set of around 300 images. I want to implement scroll view
I have an android application that currently has 9 tabs. Whenever a new tab

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.