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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:58:14+00:00 2026-06-10T12:58:14+00:00

I am new in android programming. Here is my question I tried to declare

  • 0

I am new in android programming.
Here is my question

I tried to declare an array before onCreate() method like

int[] userselected;

Note that i want to use this array to store ids of buttons user had pressed.
Then i tried to find no. of elements in this array with

int noOfElements = userselected.length;

which game me an error.
Then I changed declaration to

int[] userselected = {};

it worked, but when i tried to put an id in this array with code

userselected[1] = R.id.textview1;

it again gave me an error.
I also tried declaring array as

int[] userselected = new int[4];

but then, when i tried to find how many elements have already been stored,
userselected.length

always gave number 4.

Please tell me, how can i get what i want

  • 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-10T12:58:16+00:00Added an answer on June 10, 2026 at 12:58 pm

    You need to use ArrayList. It will give you a more flexible structure giving your case.

    ArrayList<Integer> userselected  = new  ArrayList<Integer>();
    userselected.add(R.id.textview1); //To add id.
    int noOfElement = userselected.size(); //to get size
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to xml and android programming.Here is my xml code... I don't
Hi i am new to android programming and i would like to know how
I'm fairly new to Android programming, so this may be a simple question, but
this is my first post here. I'm new in Android Programming. I want to
I'm new to android programming and not really good at java programming. Simple question
Hi I am new to android programming. Here my problem is... I designed 2
Hello I'm new to android programming. I would like to ask how can I
im new to android programming and i ran into a problem. here is the
im new in android programming.. i have a problem here. i wanna make an
New to android programming. Getting Following error. 04-07 14:49:05.452: ERROR/AndroidRuntime(1566): FATAL EXCEPTION: main java.lang.OutOfMemoryError

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.