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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:04:10+00:00 2026-06-03T22:04:10+00:00

I’m a java novice and I’ve using the code below to display a list

  • 0

I’m a java novice and I’ve using the code below to display a list of clickable TextViews that call a specific class when they are clicked.

It is a list of football team names.

Eg.

Arsenal
Manchester United
Chelsea

Clicking on TextView Arsenal (TextView id = ars) will call ars.class
Clicking on TextView Chelsea (TextView id = che)will call che.class

I have over 20 football team names.

I have an array of textview ids, which I loop through and assign them a clickable action. This works fine.

I have an string array of teamnames, the code loops through the string array and assigns each teamname to a Class object, which is used in the Intent() method.

When I run this code, the list is produced but when I click on a team name it always opens Wol.java, the last position in the string array.

I need some help with the logic, so that when I click on Arsenal it opens ars.class

Here is the code.

public final int[] teams = { R.id.ars, R.id.ast, R.id.bir, R.id.bla,
        R.id.blp, R.id.bol, R.id.che, R.id.eve, R.id.ful, R.id.hul,
        R.id.lee, R.id.liv, R.id.mid, R.id.mnc, R.id.mnu, R.id.nor,
        R.id.nwu, R.id.por, R.id.qpr, R.id.sto, R.id.sun, R.id.swa,
        R.id.tot, R.id.wes, R.id.wig, R.id.wol };

     //String array of teamnames, named to correspond their class name.
public final String[] teamnames = { "ars", "ast", "bir", "bla", "blp",
        "bol", "che", "eve", "ful", "hul", "lee", "liv", "mid", "mnc",
        "mnu", "nor", "nwu", "por", "qpr", "sto", "sun", "swa", "tot",
        "wes", "wig", "wol" };

TextView tv;
Class classname;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.m_transfers);

    setTeamNames(); //Method sets up team names to a Class name.

    for (int i = 0; i < teams.length; i++) {
        tv = (TextView) findViewById(teams[i]);
        tv.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent open = new Intent(Transfers.this, classname);
                startActivity(open);
            }
        });
    }
    ;
}

public void setTeamNames() {
    for (String s : teamnames) {
        String name = "ttj.android.ft.teams." + s;

        try {
            classname = Class.forName(name);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    ;
}
  • 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-03T22:04:12+00:00Added an answer on June 3, 2026 at 10:04 pm

    classname is being overwritten every time you iterate in the foreach loop inside setTeamNames(). Thus, only the last classname remains at the end.

    If teams and teamnames have the same number of entries (which they should), you can use the following code and get rid of setTeamNames() completely.

    final String prefix = "ttj.android.ft.teams.";
    for (int i = 0; i < teams.length; i++) {
        tv = (TextView) findViewById(teams[i]);
        tv.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
           try {
              Class class = Class.forName(prefix + teamnames[i]);               
              Intent open = new Intent(Transfers.this, class);
              startActivity(open);
            } catch (ClassNotFoundException e) {
              e.printStackTrace();
            }
        });
    }
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.