将数组列表值传递到选项卡主机但空值错误?

时间:2012-02-09 12:12:14

标签: android string arraylist

您好我正在尝试将ArrayList值传递给我的TabLayout,但我获得空值请帮助我...我成功传递了我的字符串值,但ArrayList值仅为null ...

这里我试图传递我的字符串和ArrayList值..........

这是我的代码:

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);  

            }
        });

第1和第2个值正常工作.... spec和mimage但imageList只有我得到空值......

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");

上面的代码我试着获取我的值ImageList值只显示null是什么原因?

代码:

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();

    }


}

这里我要添加到单独的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);
            }

这是我试图在标签主持人中传递的价值.......

1 个答案:

答案 0 :(得分:0)

更改您的tabview课程:

ArrayList<String> imageList;
...

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

更新:您正尝试从位于 String 的Bundle处获取 ArrayList<String>