gpt4 book ai didi

java - 使用 picasso 从加载的图像中获取 url

转载 作者:行者123 更新时间:2023-12-01 09:32:00 24 4
gpt4 key购买 nike

如何使用 picasso 获取加载的图像的 url 并将其传递给 Recyclerview 适配器中的另一个 Activity ???.

我没有找到任何从 picasso 获取网址的东西,所以如果有人可以帮助我,请告诉我在这篇文章中执行此操作的方法或代码...谢谢

package com.roa.nox.store.adapters;


import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.roa.nox.store.ApActivity;
import com.roa.nox.store.ItemObjectC;
import com.roa.nox.store.R;
import com.roa.nox.store.models.SingleItemModel;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.Locale;
import me.drakeet.materialdialog.MaterialDialog;

public class SectionListDataAdapter extends RecyclerView.Adapter<SectionListDataAdapter.SingleItemRowHolder> {

private ArrayList<SingleItemModel> itemsList;
private Context mContext;
private boolean isLang;


public SectionListDataAdapter(Context context, ArrayList<SingleItemModel> itemsList) {
this.itemsList = itemsList;

this.mContext = context;
}

@Override
public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_single_card, null);
SingleItemRowHolder mh = new SingleItemRowHolder(v);

return mh;
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public void onBindViewHolder(SingleItemRowHolder holder, int i) {

SingleItemModel singleItem = itemsList.get(i);
final int p= singleItem.getPrice();
if(p==0)
{
if (isLang = Locale.getDefault().getLanguage().equals("fa")) {
holder.price.setText("رایگان");
} else {
holder.price.setText("Free");
}
}
else
{

holder.price.setText(String.valueOf(p));
}
double rate=singleItem.getRate();
String srate= String.valueOf(rate);
holder.tvTitle.setText(singleItem.getName());
holder.dvt.setText(singleItem.getdv());
holder.cat.setText(singleItem.getcat());
holder.url.setText(singleItem.getUrl());
holder.icon.setText(singleItem.geticon());
Picasso.with(mContext).load(singleItem.geticon()).placeholder(R.drawable.load).error(R.drawable.error).into(holder.itemImage);
holder.cont.setText(singleItem.getContent());


holder.rte.setText(srate);


/* Glide.with(mContext)
.load(feedItem.getImageURL())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.centerCrop()
.error(R.drawable.bg)
.into(feedListRowHolder.thumbView);*/
}

@Override
public int getItemCount() {
return (null != itemsList ? itemsList.size() : 0);
}

public class SingleItemRowHolder extends RecyclerView.ViewHolder {

protected ImageButton btaction;
protected TextView rte;
protected TextView cat;
protected TextView price;
protected TextView tvTitle;
protected TextView dvt;
protected TextView url;
protected TextView icon;
protected TextView cont;
protected ImageView itemImage;
private Context context;

private int p;

public SingleItemRowHolder(View view) {
super(view);

this.tvTitle = (TextView) view.findViewById(R.id.tvTitle);
this.dvt = (TextView) view.findViewById(R.id.tdv);
this.price = (TextView) view.findViewById(R.id.price);
this.url = (TextView) view.findViewById(R.id.url);
this.cont = (TextView) view.findViewById(R.id.content);
this.itemImage = (ImageView) view.findViewById(R.id.itemImage);
this.btaction = (ImageButton) view.findViewById(R.id.action);
this.rte = (TextView) view.findViewById(R.id.raten);
this.cat = (TextView) view.findViewById(R.id.cat);
this.icon = (TextView) view.findViewById(R.id.icon);





view.setOnClickListener(new View.OnClickListener() {


public ItemObjectC parseImageFile;
public String iconi;

@Override
public void onClick(View v) {

final String URL = url.getText().toString();

final int pos = getAdapterPosition();
Intent intent = new Intent(mContext, ApActivity.class);
intent.putExtra("name", tvTitle.getText().toString());
intent.putExtra("price", price.getText().toString());
intent.putExtra("content", cont.getText().toString());
intent.putExtra("dev", dvt.getText().toString());
intent.putExtra("cat", cat.getText().toString());
intent.putExtra("icon", What i should to add for get url???);
intent.putExtra("rate", rte.getText().toString());
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
mContext.startActivity(intent);


}
});


btaction.setOnClickListener(new View.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(mContext, v);
popup.getMenuInflater().inflate(R.menu.popup,
popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {

switch (item.getItemId()) {
case R.id.install:



break;
case R.id.addtowishlist:


break;

default:
break;
}

return true;
}
});

}
});




}

}}

最佳答案

如果不亲自修改 picasso 库,您就无法做到这一点。幸运的是,有一种常用且易于实现的解决方法。只需使用项目的 ID/位置标记可点击元素即可。例如(如果holder.itemImage是可点击的),在onBindViewHolder()中:

holder.itemImage.setTag(position);

然后,在 onClick() 或任何处理点击的地方:

int position = (int) v.getTag();
String iconUrl = adapter.itemsList.get(position).geticon(); // make itemsList public or provide getter first

关于java - 使用 picasso 从加载的图像中获取 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39329957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com