将TypedArray传递给New Activity

时间:2018-11-02 09:17:33

标签: android android-studio android-image

我有OnCreate,其中使用TypedArray来存储在strings.xml中定义的文件列表。我有一个活动showDetailActivity,我想通过这些活动。如何将TypedArray传递给活动showDetailActivity?我阅读了有关传递对象的知识,在其中我了解到对象必须实现可仿造的内容才能通过意图传递。您的帮助将不胜感激。

TypedArray images;
@Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Resources res = getResources();
            myListView = (ListView)findViewById(R.id.myListView);

            images = res.obtainTypedArray(R.array.pictures);

            itemAdapter ItemAdapter = new itemAdapter(this, images);
            myListView.setAdapter(ItemAdapter);

            myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Intent showDetailActivity = new Intent(getApplicationContext(), DetailActivity.class);
                    showDetailActivity.putExtra("com.malcolmtanti.listapp.INDEX", i);

                    //pass TypedArray Here
                    startActivity(showDetailActivity);
                }
            });

}

0 个答案:

没有答案