0

Hi I am trying to pass my ArrayList value into my TabLayout but I am getting null value please help me...I successfully passed my string value but ArrayList value only null...

here I am trying to pass my string and ArrayList value..........

this is my code:

sdcardImages.setOnItemClickListener(new OnItemClickListener() {


            public void onItemClick(AdapterView parent, View v, int position, long id) {
                Intent intent = new Intent(ParxmlActivity.this, tabview.class);
                intent.putExtra("spec",model_List.get(position).spec);
                intent.putExtra("mimage",model_List.get(position).mimage);
                intent.putStringArrayListExtra("imageList", model_List.get(position).imageList);

                startActivity(intent);  

            }
        });

the 1st and 2nd value working fine....spec and mimage but imageList only i am getting null value......

public class tabview extends TabActivity {
    Bundle tab_intent;
    public static String spec, mimage, imageList;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.viewtab);
        tab_intent=tabview.this.getIntent().getExtras();
        spec=tab_intent.getString("spec");
        mimage = tab_intent.getString("mimage");
        imageList =  tab_intent.getString("imageList");

above code I am try to get my values the ImageList value only shows null what is the reason?

code:

package ml.ml;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

public class schild {
    public String name;
    public String model;
    public String spec;
    public String mimage;
    //public String imageList;
    //public String videoList;
    public ArrayList<String> imageList;
    public ArrayList<String> videoList;


    public schild(){
        name = new String();
        model = new String();
        spec = new String();
        mimage = new String();
        imageList = new ArrayList<String>();
        videoList = new ArrayList<String>();
        //imageList =new String();
        //videoList = new String();

    }


}

here I am adding to separate ArrayList

for(int j = 0; j<model_List.size(); j++){

                mname_List.add(model_List.get(j).name);
                mmimage.add(model_List.get(j).mimage);
                mspec_List.add(model_List.get(j).spec);
                mvideo_List.addAll(model_List.get(j).videoList);
                mmimage_List.addAll(model_List.get(j).imageList);
            }

this is value I am trying to passing in tab host.......

Natali
  • 2,934
  • 4
  • 39
  • 53
balaji
  • 1,555
  • 5
  • 26
  • 49
  • http://stackoverflow.com/questions/3939331/android-how-to-pass-arraylistcustomobject-between-activities – Samir Mangroliya Feb 09 '12 at 12:16
  • 3
    interesting ... in first Activity you're putting StringArrayList and in second you're expecting to get a String ... seems like you do not understand your own code ... – Selvin Feb 09 '12 at 12:19

1 Answers1

0

Change your tabview class:

ArrayList<String> imageList;
...

@Override
public void onCreate(Bundle savedInstanceState) {
    ...
    imageList =  tab_intent.getStringArrayList("imageList");
    ...
}

Upd: You're trying to take String from Bundle where is ArrayList<String> located.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
  • error: Type mismatch: cannot convert from ArrayList to String – balaji Feb 09 '12 at 12:23
  • change declaration of imageList – Sergey Glotov Feb 09 '12 at 12:25
  • ok i changed ArrayList imageList; now also i am getting error:The method getStringArrayList(String) in the type Bundle is not applicable for the arguments (ArrayList) – balaji Feb 09 '12 at 12:26
  • What and where did you changed? You shouldn't get this error. – Sergey Glotov Feb 09 '12 at 12:35
  • http://paste.org/45205 see this link i am getting error i changed to upd format sergey......error in this line = imageList = tab_intent.getStringArrayList(imageList); error = The method getStringArrayList(String) in the type Bundle is not applicable for the arguments (ArrayList) – balaji Feb 09 '12 at 12:41
  • Do you know Java language? Right code looks like this: `imageList = tab_intent.getStringArrayList("imageList");` – Sergey Glotov Feb 09 '12 at 12:46
  • sorry i'm beginner no error now......i wish to show this value in spinner in my audio.java tab host file...last help please..... – balaji Feb 09 '12 at 12:55
  • 1
    Ask new question about spinner. – Sergey Glotov Feb 09 '12 at 13:23