我有這段代碼,它從drawables文件夾中獲取圖像。我需要從URL獲取圖片。我認爲我可以用Picasso
做到這一點,我試過了,我不能釘它。無法從android工作室中的鏈接加載圖像
我有這樣的代碼在我的MainActivity:
public Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "image_name");
return d;
} catch (Exception e) {
return null;
}
}
private Drawable d1 = LoadImageFromWebOperations("http://uupload.ir/files/aud7_brickone.jpg");
private List<App> getApps() {
List<App> apps = new ArrayList<>();
apps.add(new App("Google+", d1, 4.6f));
apps.add(new App("Google+", d1, 4.6f));
apps.add(new App("Google+", d1, 4.6f));
apps.add(new App("Google+", d1, 4.6f));
apps.add(new App("Google+", d1, 4.6f));
apps.add(new App("Google+", d1, 4.6f));
apps.add(new App("Google+", d1, 4.6f));
return apps;
}
,這是我的適配器:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
App app = mApps.get(position);
holder.imageView.setImageResource(app.getDrawable());
holder.nameTextView.setText(app.getName());
holder.ratingTextView.setText(String.valueOf(app.getRating()));
}
這裏APP.JAVA
public class App {
private Drawable mDrawable;
private String mName;
private float mRating;
public App (String name, Drawable drawable, float rating){
mName = name;
mDrawable = drawable;
mRating = rating;
}
public float getRating(){return mRating;}
public Drawable getDrawable(){return mDrawable;}
public String getName(){return mName;}
}
我需要從圖像鏈接如:http://uupload.ir/files/aud7_brickone.jpg
我無法實現!
你想從繪製文件夾或遠程圖像的圖像? – Rajesh
遙控!但我需要它轉換爲「int」 –