简体   繁体   English

如何将下载的图像从一个活动传递到下一个活动?

[英]How do I pass a downloaded image from one activity to the next?

I would like to take a downloaded image the user clicked on from on activity to the next. 我想将用户单击的下载图像从活动中移至下一个。 I believe this should be done in my lambda onItemClickListenerClass. 我相信这应该在我的lambda onItemClickListenerClass中完成。

My code for my custom adapter class is here: 我的自定义适配器类的代码在这里:

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Movie movie = getItem(position);
      if  ( movie == null) return null;


        ImageView imageView;
        /**
         * if convertView is empty, set it equal to ImageView
         */
        if (convertView == null) {
            imageView = new ImageView(context);


            imageView.setLayoutParams(new GridView.LayoutParams(width, height));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        } else {
            imageView = (ImageView) convertView;
        }

        Uri coverUrl = movie.getMovieCover();
        Picasso.with(context)
                .load(coverUrl)
                .into(imageView);

        //    Log.e(LOG_TAG, "URL " + url);


        return imageView;
    }

and this is code from my Object constructor class 这是我的Object构造函数类中的代码

public Uri getMovieCover(){
      final String BASE = "http://image.tmdb.org/t/p/w185";

    Uri builtUri = Uri.parse(BASE).buildUpon()
            .appendEncodedPath(poster_path)
            .build();

    return builtUri;
}

I have bundled all my string data into an extra and passed it through an intent, and I was thinking of doing the same thing in this context by converting the image into an extra and pass it through the intent, but I currently do not know how to implement that. 我已将所有字符串数据捆绑到一个附加文件中并通过意图传递,并且我正在考虑在此上下文中通过将图像转换为附加文件并通过该意图传递来做相同的事情,但是我目前不知道如何实现这一点。

Can anyone help me with this problem? 谁能帮助我解决这个问题? I am currently doing the Udacity Android Programmer final project so I still am fairly new to android programming. 我目前正在做Udacity Android Programmer的最终项目,所以我对android编程还是很陌生。

Pass the Url as String extra to 2nd Activity. 将Url作为字符串额外传递给第二活动。

In 1st Activity/Custom Adapter : 在第一个活动/自定义适配器中:

String url = "http://image-url";
Intent intent = new Intent (getActivity().this, 2ndActivity.class);
intent.putExtra("image-url", url);
getActivity().startIntent(intent);

In 2nd Activity : 在第二活动中:

String url;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent i = getIntents();
    url = i.getExtra("image-url");

    Uri coverUrl = new Uri(url);

    if (url.Length() > 0) {
        imageView = new ImageView(context);
        imageView.setLayoutParams(new GridView.LayoutParams(width, height));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        Picasso.with(context)
                .load(coverUrl)
                .into(imageView);
    }
}

我如何通过 ArrayList<object> 从一个活动到另一个活动<div id="text_translate"><p>我想将 Object 的 ArrayList 从一个活动传递到另一个活动。</p><p> 这是示例代码:</p><pre> { ArrayList&lt;object&gt; list=new ArrayList&lt;&gt;(); Object value[]=new Object[m.size()]; int n=0; value[]=new Object[n]; value[n]=data.getName("name"); value[n]=data.getLocation("location"); list.add(value[n]); n++; //Since there are "n" number of object } //here the value a which is ArrayList Object // which I want to pass it from here to another activity.</pre><p> 那么现在我将如何将 object 从这里传递给另一个活动。 <strong>但是</strong>,我可以使用<strong>Gson</strong>获得值。 通过将值转换为<strong>json</strong>并将其作为字符串传递给<strong>SharedPreference</strong>并从另一个活动中检索,然后使用<strong>类型</strong>从<strong>Json</strong>转换回来以支持其原始形式。</p><p> 我想知道是否可以使用<strong>Parceable</strong>传递值。 因为我在使用它时得到了 null 值。</p><p> 这是我试图使我的 Object 变量 Parceable 的代码:</p><pre> public class ProductList implements Parcelable { private String NAME; private String LOCATION; public ProductList() { } protected ProductList(Parcel in) { LOCATION= in.readString(); NAME= in.readString(); } public static final Creator&lt;ProductList&gt; CREATOR = new Creator&lt;ProductList&gt;() { @Override public ProductList createFromParcel(Parcel in) { return new ProductList(in); } @Override public ProductList[] newArray(int size) { return new ProductList[size]; } }; public String getNAME() { return NAME; } public void setNAME(String NAME) { this.NAME= NAME; } public String getLOCATION() { return LOCATION; } public void setITEM_IMAGE(String LOCATION) { this.LOCATION= LOCATION; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(NAME); dest.writeString(LOCATION); } }</pre></div></object> - How do I pass ArrayList<Object> from one Activity to another Activity

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用图像路径从一个活动传递到另一个活动? - how do i pass image using image path from one activity to another? 如何将数据从一个活动传递到下一个活动 - How to pass the data from one Activity to the next activity 我如何通过 ArrayList<object> 从一个活动到另一个活动<div id="text_translate"><p>我想将 Object 的 ArrayList 从一个活动传递到另一个活动。</p><p> 这是示例代码:</p><pre> { ArrayList&lt;object&gt; list=new ArrayList&lt;&gt;(); Object value[]=new Object[m.size()]; int n=0; value[]=new Object[n]; value[n]=data.getName("name"); value[n]=data.getLocation("location"); list.add(value[n]); n++; //Since there are "n" number of object } //here the value a which is ArrayList Object // which I want to pass it from here to another activity.</pre><p> 那么现在我将如何将 object 从这里传递给另一个活动。 <strong>但是</strong>,我可以使用<strong>Gson</strong>获得值。 通过将值转换为<strong>json</strong>并将其作为字符串传递给<strong>SharedPreference</strong>并从另一个活动中检索,然后使用<strong>类型</strong>从<strong>Json</strong>转换回来以支持其原始形式。</p><p> 我想知道是否可以使用<strong>Parceable</strong>传递值。 因为我在使用它时得到了 null 值。</p><p> 这是我试图使我的 Object 变量 Parceable 的代码:</p><pre> public class ProductList implements Parcelable { private String NAME; private String LOCATION; public ProductList() { } protected ProductList(Parcel in) { LOCATION= in.readString(); NAME= in.readString(); } public static final Creator&lt;ProductList&gt; CREATOR = new Creator&lt;ProductList&gt;() { @Override public ProductList createFromParcel(Parcel in) { return new ProductList(in); } @Override public ProductList[] newArray(int size) { return new ProductList[size]; } }; public String getNAME() { return NAME; } public void setNAME(String NAME) { this.NAME= NAME; } public String getLOCATION() { return LOCATION; } public void setITEM_IMAGE(String LOCATION) { this.LOCATION= LOCATION; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(NAME); dest.writeString(LOCATION); } }</pre></div></object> - How do I pass ArrayList<Object> from one Activity to another Activity 如何将一个JSON的ID传递给下一个Activity? - How to pass ID of one JSON to next Activity? 我如何将数据从一个活动传递到另一活动 - how i pass data from one activity to another activity 如何在Java Swing中将数据从数组从一种形式传递到另一种形式? - How do I pass data from an array from one Form to the next in Java Swing? 如何将值从列表视图传递到下一个活动 - How to pass value from listview to the next activity 如何将信息从一个活动的EditText传递到另一个活动,以将URL加载到该新活动的WebView中? - How do I pass info from one activity's EditText to another for the url to be loaded in that new activity's WebView? 如何在单独的活动中从一个活动修改ArrayList - How do i modify an ArrayList from one Activity in a separate Activity 如何将数据正确地从一项活动传递到另一项活动? - how can I pass data correctly from one activity to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM