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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:04:08+00:00 2026-05-26T17:04:08+00:00

I am an android newbie so forgive me if this question is simple. Basically

  • 0

I am an android newbie so forgive me if this question is simple.

Basically I want to port over a java project to Android. By view components in my java application dynamically change depending on the model. I.e the model being display may require n check boxes or n radio boxes depending on the enum TYPE being passed to the view.

In my java display this is achieved by nested loops with the n number each time adding the component to the screen. e.g a simplified version of the code:

if (type == TYPE.CHECKBOXES){
for (int i = 0; i < n ; i++){
add(new JCheckBox()); 
}}

This is processed for the view each time a next button is pressed (the type changes each time). In android how do i dynamically add and remove components, or do i need to set up a new view for each type?

Many thanks
Sam

  • 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-26T17:04:08+00:00Added an answer on May 26, 2026 at 5:04 pm

    In Java you manage your layouts using JPanel alongwith specific layouts (i.e BorderLayout, FlowLayout etc.)
    you add your components to JPanel and then add your JPanel to parent or root layout.

    a little example (as you posted:)

    if (type == TYPE.CHECKBOXES){
         for (int i = 0; i < n ; i++){
              mayPanel.add(new JCheckBox()); 
         }
    }
    

    In android you manage your layouts using ViewGroup which has specific subclassed layout design (i.e LinearLayout much like as FlowLayout, RelativeLayout may be considered BorderLayout)

    You can use these layouts just like a JPanel

    if (type == TYPE.CHECKBOXES){
         LinearLayout myPanel = new LinearLayout(this);
         for (int i = 0; i < n ; i++){
              CheckBox chk=new CheckBox(this);  
              chk.setText("Hello");
              myPanel.addView(chk); 
         }
         myRootPanel.addView(myPanel);
    }
    

    Just an addition: The Component in Java are called View in Android. Most of the control (also called widgets like Button, EditText, ImageButton, ImageView) in Android are subclass of View.

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

Sidebar

Related Questions

I am a newbie to Android and Java and want to write a function
Forgive me if this is a newbie question, but... When playing video, is it
I'm an Android newbie so I apologize if this is a dumb question .
I am a learning via a book so please forgive this newbie question. I
I am newbie to android. I have client server based application. Server keeps on
i'm newbie for android dev, now i want explore file handling in android, for
Newbie question. After I have written the Android App (easy part) I need to
I’m currently working on a Android project and is very newbie to the Android
I apologize in advance for the newbie nature of this question. Here is my
I am an Android Newbie and I'm developing Go game application for android. I'm

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.