0

hi im trying to use and intent to send information of the name and the photos of my google+ frinds and i am tryin to show them on another activity but the problem is that it show only one friend like 20 times... dont know what to do...please help

here's my code:

MainActivity.java:

if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) {
           // mCirclesList.clear();
            PersonBuffer personBuffer = peopleData.getPersonBuffer();

            try {
                int count = personBuffer.getCount();
                for (int i = 0; i < count; i++) {

                    Log.i("Google", "Requesting visible circles");                      
                    Intent toMainActivity2= new Intent(MainActivity.this,MainActivity2.class);
                    toMainActivity2.putExtra("NameURL",personBuffer.get(i).getDisplayName());
                    toMainActivity2.putExtra("PhotoURL",personBuffer.get(i).getImage().getUrl());
                    toMainActivity2.putExtra("Count", count);
                    Log.i("Google", "Sending visible circles");
                    startActivity(toMainActivity2);
                }
            } finally {
                personBuffer.close();
            }

        }

and here's my MainActivity2:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        mCirclesListView = (ListView) findViewById(R.id.circles_list);
        aa=new FancyAdapter();
        mCirclesListView.setAdapter(aa);
        aa.notifyDataSetChanged();
        Intent retrieveInformation = getIntent();
        int count = retrieveInformation.getExtras().getInt("Count");

            for (int i = 0; i < count; i++){

            String NameURL = retrieveInformation.getExtras().getString("NameURL");
            mCirclesList.add(NameURL);
            String PhotoURL = retrieveInformation.getExtras().getString("PhotoURL");
            mCirclesList2.add(PhotoURL);
            Log.i("Google", "Recieving visible circles");
        }
}

    class ViewHolder{
        ImageView profilePhoto;
        TextView profileName;
    }

    class FancyAdapter extends ArrayAdapter<String> {

        FancyAdapter(){
            super(MainActivity2.this,android.R.layout.simple_list_item_1,mCirclesList);
        }
        public View getView(int position,View convertView, ViewGroup parent){
            Log.i("Google", "getView");

            ViewHolder holder;
            if (convertView==null){
                LayoutInflater inflater=getLayoutInflater();
                convertView=inflater.inflate(R.layout.custom_list_item,null);
                holder=new ViewHolder();
                holder.profileName=(TextView) convertView.findViewById(R.id.textView);
                holder.profilePhoto=(ImageView) convertView.findViewById(R.id.imageView);
                convertView.setTag(holder);
                Log.i("Google","Using ViewHolder");
            }else{
                holder=(ViewHolder) convertView.getTag();

            }

            holder.profileName.setText(mCirclesList.get(position));
            Picasso.with(MainActivity2.this)
                    .load(mCirclesList2.get(position))
                    .resize(50, 50)
                    .config(Bitmap.Config.ARGB_4444)
                    .error(R.drawable.abc_btn_radio_to_on_mtrl_015)  // en caso de no tener imagen pone la de la dirección
                    .into(holder.profilePhoto);
            Log.i("Google","Recycling Shit whith the ViewHolder");
            return convertView;

        }
    }
Andrey Solera
  • 2,311
  • 2
  • 26
  • 51

1 Answers1

0

You are sending an intent to an activity with only one of your friends. You should start the activity only once and send as an extra the information about all your friends in one intent. Otherwise you are starting the activity once per friend and only send the information about that friend. So when your activity gets the last intent it has only the information about the last friend and every time in the for gets the same information. I hope you understand. If you need I can help you further

Martina
  • 23
  • 4
  • You can use something like this http://stackoverflow.com/questions/18050030/intent-putextra-arraylistnamevaluepair to send the whole arraylist in one intent and start the activity only once, then you don't need the for in the first activity – Martina Mar 27 '15 at 18:03
  • hi! sorry i dont understand how can I can start the activity only once... please help ive been struggling for days with this – Andrey Solera Mar 28 '15 at 06:02
  • To start the activity only once you need to send the whole list of friends to that activity. So, to pass a list as an extra in the intent, you need to create a list of objects that implements serializable or parcelable. So you should create an object that contains the name and photo for each friend and that object needs to implement Serializable o Parcelable (http://developer.android.com/reference/android/os/Parcelable.html). Parcelable is recommended aproach for Android but can be harder to achieve. Then you pass this array as an extra using intent.putParcelableArrayListExtra("key", value); – Martina Mar 28 '15 at 18:22
  • Then on MainActivity2 get that extra from the intent and get the information from each object – Martina Mar 28 '15 at 18:23
  • on the for, i have implemented an if sending the whole list when the for is finished, therefore sending the whole ArrayList, but the arralist is not beeing displayed i dont know why.. a have putted Log's and everything seems to work fine – Andrey Solera Mar 28 '15 at 21:31
  • I'm glad you made it :) – Martina Mar 29 '15 at 17:24