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

The Archive Base Latest Questions

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

I am trying to show just the name of the player from the array

  • 0

I am trying to show just the name of the player from the array into the list view. this is my code for that:

player_List.setAdapter(new ArrayAdapter<Player>(this, android.R.layout.simple_list_item_1, dataStore.getPlayers()));

im getting all the information from that array using this call. i am unsure how to just call the name.

this is the coding for my data store:

/**
 * This class is essentially a global library for the Scoresheet.
 * It provides methods through which the Players and Teams can be accessed
 * from any part of the application.
 * The saving/loading of application data will also be handled through this
 * class.
 * 
 * You can access this DataStore by calling:
 * DataStore dataStore = ((DataStore)getApplicationContext());
 * From any Activity
 */
public class DataStore extends Application {

    // Create ArrayLists to hold all our Player and Team objects
    private ArrayList<Player> players = new ArrayList<Player>();
    private ArrayList<Team> teams = new ArrayList<Team>();

    // File names for our internal storage:
    private String playerFileName = "players";
    private String teamFileName = "teams";

    /**
     * Add a Player object to the list of players.
     * @param p The Player object to add
     */
    public void addPlayer(Player p){
        this.players.add(p);

    }

    /**
     * Merge an ArrayList of Player objects with the current collection of Players
     * @param players ArrayList of Player objects to add to the collection
     */
    public void addPlayers(ArrayList<Player> players){
        Iterator<Player> it = players.iterator();
        while (it.hasNext()){
            this.players.add(it.next());
        }
    }

    /**
     * Return an ArrayList of player objects containing all Players 
     * @return
     */
    public ArrayList<Player> getPlayers(){
        return this.players;
    }

and this is my player class:

public class Player implements Serializable{
    // Randomly generate serial ID
    private static final long serialVersionUID = 7423594865734681292L;
    private static int ID = 0;  // Class variable
    public String name;
    private int id;

    public Player(String name) throws Exception{
        this.setId(ID);
        ID++;               // Increment class ID counter
        if (!this.setName(name))
            throw new Exception("Invalid Name");    // This is the only way to prevent the object being instantiated if it has an invalid name
    }

    public String getName() {
        return name;
    }

    /**
     * Set the players name as desired.
     * @param name
     * @return true on success, false on fail
     */
    public boolean setName(String name) {
        // Only update the name if we are actually given a string
        boolean success = false;
        name = name.trim();
        if (!name.equals("")){
            this.name = name;
            success = true;
        }
        return success;
    }

    public int getId() {
        return id;
    }

    private void setId(int id) {
        this.id = id;
    }

}
  • 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:16:30+00:00Added an answer on June 1, 2026 at 1:16 pm

    Use CustomAdapter and set in getView(...) method

    Like,

    Player player = getPlayers().get(position);
    textview.setText(player.name)
    

    see this example,,
    http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

    http://jnastase.alner.net/archive/2010/12/19/custom-android-listadapter.aspx

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

Sidebar

Related Questions

Can someone please show me how i can preg_match this so that it just
I'm just trying to show the name of the months based on the current
Just trying out Mongoid at the moment, I've run into an issue that's probably
I'm trying to get a single result from my database, just one name. I
I am trying to apply filters to employees to show them just on the
I'm trying to show a UIAlertView before actually deleting a cell from a UITableView
I'm trying to show a list of links (in index.html) to text files in
I'm trying to show a simple countdown from 2 hours like so: $(function ()
I am trying to get the branch name from a given tag. I tried
Im trying to stop showing the repeats in a array and show them once.

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.