Pase el elemento ArrayList al siguiente intento

I'd like to pass an ArrayList element to the next Intent, if some one can help me!

try{
                JSONArray jArray = new JSONArray(result);
                JSONObject json_data=null;
                for(int i=0;i<jArray.length();i++)
                {
                   json_data = jArray.getJSONObject(i);
                   r.add(json_data.getString("Nom_Serveur"));
               }
               setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, r));
               ListView list = getListView();
               list.setTextFilterEnabled(true);
               list.setOnItemClickListener(new OnItemClickListener(){

                public void onItemClick(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    Intent i = new Intent(Serveur_EnPanne.this, Info_serveur.class);
                    i.putExtra("key", ??)
                    startActivity(i);   

                }

preguntado el 10 de marzo de 12 a las 13:03

3 Respuestas

hazlo de esta manera:

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
         Intent i = new Intent(Serveur_EnPanne.this, Info_serveur.class);
         i.putExtra("key", arg0.getSeletectedItem().toString());
         startActivity(i);
}

or

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
         Intent i = new Intent(Serveur_EnPanne.this, Info_serveur.class);
         i.putExtra("key", r.get(arg2));
         startActivity(i);
}

respondido 10 mar '12, 14:03

With r.get(arg2)) how it will retrieve it in other class ? - oussemos

Use this code.Here arraylist is your arraylist.

ArrayList<String[]> arraylist=new ArrayList<String[]>();
  intent = new Intent(this,Your.class);
        intent.putExtra("al2", arraylist);

To retrieve it in other class

Bundle extras = getIntent().getExtras();
arraylist= extras.getStringarray("al2");

respondido 10 mar '12, 14:03

arraylist is parse by the following method

putIntegerArrayListExtra(String name, ArrayList<Integer> value)

putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)

putStringArrayListExtra(String name, ArrayList<String> value)

putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value)

Then you can read from you next activity by replacing put with get with key string as argument,eg

myIntent.getStringArrayListExtra("arrayPeople");

Onother method of passing the arraylist is by bundle:

Intent i = new Intent(this,name.class);
Bundle b = new Bundle();
b.putIntegerArrayListExtra(String name, ArrayList<Integer> value);
//b.putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value);
//b.putStringArrayListExtra(String name, ArrayList<String> value);
i.putExtra(String name,b);
startActivity(i);

Getting the data to another intent by :

Bundle b = getIntent().getExtra().putParcelableArrayListExtra(String name);

Espero que esto te ayude.

respondido 10 mar '12, 14:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.