开发者

Pass Image Array to next screen

I've a dynamic image array which come through from database. And i just show image thumbnails at first screen and want to display full screen of same image array. The thing is that i want to pass the whole dynamic array to next screen. Actually i know how to use preferences in java. But i don't know how to pass the whole array with variables or something. Any ideas would be appreciate.

public class MerchantDetails extends GLCityActivity implements OnClickListener {
    public static MerchantDetails instance;
    private Gallery gallery;
    private ImageView imView;

    String Header, contentName;
    DBManager gDatabase = new DBManager(this);
    private ArrayList<Multimedia> mm;
    private ImageViewAdapter iva;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.Theme_Translucent);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.details);
        instance = this;
        initActivity(instance, " ");
        try {
            gDatabase.createDataBase();
        } catch (IOException e) {
            throw new Error("Unable to create database");
        }

        try {
            gDatabase.openDatabase();
        } catch (SQLiteException sqle) {
            throw sqle;
        }
        settingLayout();
    }

    public void settingLayout() {
        SharedPreferences preferences = getSharedPreferences(
                Constants.DEFAUL_SHARE_DATA, 0);
        Header = preferences.getString("SubName", "");



        headerTxt = (TextView) findViewById(R.id.templateTopTitleTView);
        headerTxt.setText(Header);

        gallery = (Gallery) findViewById(R.id.gallery);
        if (mm.isEmpty()) {
            gallery.setVisibility(gallery.INVISIBLE);
        } else {
            gallery.setAdapter(iva);
            gallery.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView parent, View v,
                        int position, long id) {
                    SharedPreferences preferences = getSharedPreferences(
                            Constants.DEFAUL_SHARE_DATA, 0);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putString("ImagePosition", mm.get(position) + "");
                    editor.putInt("ImageLength", mm.size());
                    Intent viewer = new Intent(instance, GalleryViewer.class);
                    startActivityForResult(viewer, 0);
                    if (editor.commit()) {

                    }

                }
            });
        }
    }

    private class ImageViewAdapter extends ArrayAdapter<Multimedia> {

        private ArrayList<Multimedia> items;

        public ImageViewAdapter(Context context, int textViewResourceId,
                ArrayList<Multimedia> items) {
            super(context, textViewResourceId, items);
            this.items = items;

        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.image_list, null);
            }
            Multimedia info = items.get(position);
            if (info != null) {
                ImageView imView = (ImageView) v
                        .findViewById(R.id.rowlistIconIView);
                String name = info.thumbnail;
                String[] test = gDatabase.split(name, ".");
                int resID = getResources().getIdentifier(test[0], "drawable",
                        getPackageName());
                Log.v("Log", name + ";" + resID + ";" + test[0] + ";");
                try {
                    imView.setImageResource(resID);
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
            return v;
        }
    }
}

Edited : @Jeremy Edwards,thanks for your reply. I tried to do as you suggest but i found this error while i coded. I tried to use putExtra(String name,int[] value) but the error said The method putExtra(String name,boolean value) in the type Intent is not applicable for the a开发者_C百科rguments (String,Multimedia). Actually i already chose putExtra(String name,int[] value) from auto suggest box. wonder how it change back to (String name,int[] value) suddenly. Please check my code below. private ArrayList<Multimedia> mm; viewer.putExtra("ImagePosition",mm.get(position)); viewer.putExtra(String name,int[] value)


For the viewer Intent. Use Intent.put(name, "Id of the image").

Then in the viewer activity use getIntent().getIntExtra(name) to get that id back.

I'd advise against passing image data itself since android uses IPC "Shared memory" to pass data between the activity boundaries. It was meant to be lightweight.

The viewer activity should get the ID and then hit the DB for the full blown image you want. You shouldn't need to use preferences either to accomplish this since the Bundle inside the Intent object will carry the information you need.


From scanning through your code I think you are storing the images in ArrayList.

ArrayList is Serializable so you can use bundle to pass it to the next screen. You can use bundle's putSerializable method

Something like this

Bundle bundle = new Bundle();
bundle.putSerializable(<key>, <your serializable obj>);

then use the getSerializable() to get it back

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜