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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:15:44+00:00 2026-06-18T15:15:44+00:00

I am working on to use the horizontal pager by using this Github Project

  • 0

I am working on to use the horizontal pager by using this Github Project https://github.com/ysamlan/horizontalpager
. This is working fine and performing the horizontal swaping. But in my Project i have added the layout, Buttons and Radio Buttons dynamically. The Radio buttons changes their state on horizontal paging when they are placed statically but i have placed them dynamically so the RadioGroup.OnCheckedChangeListener is not working.

My Main class is

package com.PointofSale;

import java.util.List;
import database.in.*;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.view.ViewPager.LayoutParams;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DigitalClock;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

public class SalesActivity extends Activity{
    private HorizontalPager mPager;
    private RadioGroup mRadioGroup;
    com.PointofSale.HorizontalPager horizontalPager;
    ProductDbHandler prodDbHand;
    Cursor mCursor;
    RelativeLayout deptSysKeys;
    RadioButton[] rb;
    int number_Of_Pages;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sale_layout);
        DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
        prodDbHand=new ProductDbHandler(this);
        mPager=(HorizontalPager)findViewById(R.id.horizontal_pager);
        mRadioGroup=(RadioGroup)findViewById(R.id.radioGroup);
        deptSysKeys=(RelativeLayout)findViewById(R.id.DeptKeyslayout);
        List<GetDeptInfo> getDept = prodDbHand.getAllDept();  
        int deptSize=getDept.size();
        number_Of_Pages=(deptSize/5+1);
        rb = new RadioButton[number_Of_Pages];
        ((ViewGroup)mRadioGroup.getParent()).removeView(mRadioGroup);
        for(int i=0; i<number_Of_Pages; i++){
            rb[i]  = new RadioButton(this);
            //rb[1].setChecked(true);
            rb[i].setId(i);
            mRadioGroup.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout
        }
        rb[0].setChecked(true);
        deptSysKeys.addView(mRadioGroup);//you add the whole RadioGroup to the layout
        final LinearLayout[] keysLayout=new LinearLayout[number_Of_Pages];
        com.PointofSale.HorizontalPager.LayoutParams llp = new  com.PointofSale.HorizontalPager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
        Button[] deptBtn=new Button[deptSize];
        int[] DeptId=new int[deptSize];
        String[] DeptName=new String[deptSize];
        int k=0;
        int a=0;
        for(int i=0;i<number_Of_Pages;i++){
            keysLayout[i]=new LinearLayout(this);
            keysLayout[i].setOrientation(LinearLayout.HORIZONTAL);
            keysLayout[i].setId(i);
            System.out.println("LinerLayout Created:"+i);
            keysLayout[i].setLayoutParams(llp);
            for(int j=a;j<deptSize;j++){
                deptBtn[j]=new Button(this);
                deptBtn[j].setText(getDept.get(j).getName());
                System.out.println("Departments:"+getDept.get(j).getName());
                deptBtn[j].setId(getDept.get(j).getID());
                keysLayout[i].addView(deptBtn[j]);
                k++;
                if(k==5){
                    break;
                }
            }
            k=0;
            a=a+5;
            mPager.addView(keysLayout[i]);
        } 
    } 
    private final HorizontalPager.OnScreenSwitchListener onScreenSwitchListener =
            new HorizontalPager.OnScreenSwitchListener() {
                @Override
                public void onScreenSwitched(final int screen) {
                    // Check the appropriate button when the user swipes screens.
                    /*switch (screen) {

                        case 0:
                            mPager.setCurrentScreen(0, true);
                           // mRadioGroup.check(R.id.rg[0]);
                            break;
                        case 1:
                            mPager.setCurrentScreen(1, true);
                          // mRadioGroup.check(R.id.radio_btn_1);
                            break;
                        case 2:
                            mPager.setCurrentScreen(2, true);
                            //mRadioGroup.check(R.id.radio_btn_2);
                            break;
                        default:
                            break;
                    }*/

                    for(int i=0; i<number_Of_Pages;i++){
                        if(screen==i){
                            mPager.setCurrentScreen(i, true);
                            //RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i);
                            mRadioGroup.check(rb[i].getId());
                            System.out.println("Radio Button ID:"+rb[i].getId());
                        }
                    }
                }
            };

          private final RadioGroup.OnCheckedChangeListener onCheckedChangedListener =
            new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(final RadioGroup group, final int checkedId) {
                    // Slide to the appropriate screen when the user checks a button.
                     /*switch (checkedId) {
                        case btn.getId():
                            mPager.setCurrentScreen(0, true);
                            break;
                        case btn.getId():
                            mPager.setCurrentScreen(1, true);
                            break;
                        case btn.getId():
                            mPager.setCurrentScreen(2, true);
                            break;
                        default:
                            break;
                    }*/
                    for(int i=0; i<number_Of_Pages;i++){
                        if(checkedId==i){
                            mPager.setCurrentScreen(i, true);

                        }
                    }

                }
            };


}

The code static code to change the Radio buttons state is commented above. Suggest me something that where i am wrong and any help is appriciated.

  • 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-18T15:15:46+00:00Added an answer on June 18, 2026 at 3:15 pm

    You do not call setOnCheckedChangeListener on your RadioButton object

     for(int i=0; i<number_Of_Pages; i++){
            rb[i]  = new RadioButton(this);           
            rb[i].setId(i);
    
            // Add this line to register your onCheckedChangedListener handler
            rb[i].setOnCheckedChangeListener(onCheckedChangedListener);
            mRadioGroup.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The guys I'm working with use Eclipse as their IDE and I'm using Sublime.
I'm using VS2010. The projects that I'm working on use different source control providers,
I'm working on a new CMS to use on repeative projects. Basically this chunk
I'm working in a horizontal layout, and trying use jquery to when click in
I'm making a horizontal scroller using jQuery. I have it working using the following
I'm using the scrollTo plugin for a horizontal website and it works fine. I
I am working on an Android project in which I use a ViewFlipper for
I am using an horizontal accordion from here: http://www.dynamicdrive.com/dynamicindex17/haccordion.htm I got it to display
First, I am using Wordpress for this project but I don't think this issue
I am working to use django's ContentType framework to create some generic relations for

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.