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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:14:25+00:00 2026-06-01T13:14:25+00:00

I am new to programming but had some spare time and just got a

  • 0

I am new to programming but had some spare time and just got a new android tablet so thought its time to learn. I play a board game that has MANY decks that you draw from throughout the course of the game and decided it would be nice to simply have an application showing the 21 decks and you click on one and it randomly displays a card from one of those decks. You read the card, act on it, click on the card and it disappears.

i thus have a layout with all 21 decks (7×3) each an individual button. Thus i have 21 buttons on the 1 screen. According to the tutorial i have been following i need to declare the buttons on the .java file button1 = (Button) findViewById(android.R.id.button1). but it only has the option to declare 3 buttons after which i get the little red x of doom.

How do i go about declaring all 21 buttons? Or do i not need to declare these buttons?

Any help would be great! (may also need help finding a way to randomize the “draw” feature so don’t be surprised to see me again)

  • 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-01T13:14:27+00:00Added an answer on June 1, 2026 at 1:14 pm

    If you laid out each button in XML (main.xml or something similar), then yes, if you wish to have them do anything, you have to declare the buttons as you said.

    Button button1 = (Button) findViewById(R.id.button1);
    

    By typing it this way, I assume you didn’t declare the buttons higher up in your code, as class-wide fields. Also, have you run the method setContentView(R.layout.main);?

    So let’s just be clear: unless you type Button b1; Button b2; Button b3 just below your class line (public class YourClassName() {, each time you try to instantiate a button, you have to say Button b1 = (Button) findViewById(R.id.button1);. If you did make class-wide fields (right below the class line) then you can have code like you showed in your original question, where it’s just button1 = (Button) findViewById(R.id.button1). Does this distinction make sense?

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

Sidebar

Related Questions

I'm new to Android & Java programming but have been programming in .NET for
I'm new to web programming, but I had an idea I could use as
I'm very very new to programming in Python, but out of necessity I had
I am new to Cocoa programming (but relatively experienced with other UI frameworks) and
I'm fairly new to C programming but trying my best to understand it. I
I've done a fair bit of mysql php programming but am pretty new to
Im new to programming and I dont know very much about but I'm making
I'm new in programming windows phone 7 but get really tired cuz i spend
I'm fairly new at programming, but I've wondered how shell text editors such as
I'm fairly new to programming and new to java, but I'd like to jump

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.