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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:16:13+00:00 2026-06-04T14:16:13+00:00

My array list somehow becomes populated. Look at this code: final ListView list =

  • 0

My array list somehow becomes populated.

Look at this code:

final ListView list = getListView();
boolean threadNeeded = true;
//settings
list.setItemsCanFocus(false);
Bundle extras = getIntent().getExtras();
allFriends = getIntent().getParcelableExtra("shibby.whisper.allFriends");
selectedFriends = getIntent().getParcelableExtra("shibby.whisper.selectedFriends");
System.out.println("JUST ENTERED ACTIVITY : "+selectedFriends.getPositions());

if(extras !=null) {
    maxPlayers = extras.getInt("max_players");
}

if(allFriends != null){
    if(!allFriends.getIds().isEmpty()){
        threadNeeded = false;
    }
}

if(selectedFriends == null){
    System.out.println("selectedFriends is null before callback from ListActivity");
    selectedFriends = new PlayerList();
}

list.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        FacebookFriendsAdapter a = (FacebookFriendsAdapter) list.getAdapter();
        //select item
        boolean isSelected = a.toggleSelected(new Integer(position));

        //if reached maximum players and have selected a new user
        if(((maxPlayers+1 == a.getMaxPlayersCounter() && maxPlayers != 0) && isSelected)
            || (maxPlayers == 0 && a.getMaxPlayersCounter() == maxAvailablePlayers+1)){
            Log.e("addfriends","Max Players Reached");
            a.toggleSelected(new Integer(position));        
            final Dialog dialog = new Dialog(FacebookFriendsListActivity.this, R.style.CustomDialogTheme );
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.maxplayers);
            dialog.setCancelable(true);
            // set the custom dialog components - text, image and button
            Button dialogButton = (Button)       dialog.findViewById(R.id.max_players_dismiss_btn);
            // if button is clicked, close the custom dialog
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
            dialog.show();
        }
    }
});

m_friends = new ArrayList<Player>();
this.m_adapter = new FacebookFriendsAdapter(this, R.layout.facebbok_friends_item, m_friends);

//set the selected friends on the adapter to remember earlier picks
if(selectedFriends != null){
    oldPositions = selectedFriends.getPositions();
    m_adapter.setSelectedIds(selectedFriends.getPositions());
    m_adapter.setMaxPlayersCounter(selectedFriends.getIds().size());
    System.out.println("Max player selected Is : "+maxPlayers+" And Selected Players Counter Is :" +m_adapter.getMaxPlayersCounter());
}

When the activity starts, the selectedFriends.getPosition() returns empty.

When I click a button I do this action:

if(oldPositions != null){
    System.out.println("This is old positions : " + oldPositions);
}

Which is populated (by the new position), but I don’t see why. Am I referencing something I shouldn’t? Do I override the data in memory?

EDIT : This happens after I select some friends from the ListView. toggleSelected() adds or removes item from an inner ArrayList.

  • 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-04T14:16:14+00:00Added an answer on June 4, 2026 at 2:16 pm

    I think your mistake is assuming that this line makes a copy of whatever getPositions return:

    oldPositions = selectedFriends.getPositions();
    

    Actually it only makes a copy of the reference – it doesn’t make a shallow copy of the entire list.

    You probably want something like this (I’m just guessing the type):

    oldPositions = new ArrayList<Position>(selectedFriends.getPositions());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array list of objects and I am using this example to
I'm using code from this page http://code.google.com/apis/contacts/docs/1.0/developers_guide_js.html to get list of gmail contacts. Actually
Example: list($fruit1, $fruit2) = array('apples', 'oranges'); code above of course works ok, but code
I have an array list of objects in my application. private static ArrayList<Player> userList=new
How to read an array list & print it in prolog ? I need
I have an array list named newSymptomList which contains a list of Symptom id's
I have a collection (or list or array list) in which I want to
Hello Sir i am pass array list through url android to php my arraylistvalues[x,y.z,....]
I want to keep some data which is checkhed in array list. I added
I am trying to add the contents of my array list to an AlertDialog,

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.