将btimap发送给另一项活动

时间:2016-05-18 23:48:48

标签: android fragment android-recyclerview

我正在尝试将图像发送到我的ercyclerview片段中的活动,现在我不知道该怎么做。新手()。 这是我的适配器

    @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.r_view, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final Place place = new PlaceData().propertyList().get(position);
    holder.homeTextView.setText(place.name);
    holder.address.setText(place.addressname);
    holder.prices.setText(place.prices);

    //loading image to the main home imageview
    Picasso.with(mcontext).load(path).fit().centerCrop().into(holder.mainImageview);

    holder.mainImageview.

}

@Override
public int getItemCount() {
    return new PlaceData().propertyList().size();
}


public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public LinearLayout mainHolder;
    public LinearLayout placeNameHolder;
    public ImageView mainImageview;
    public TextView homeTextView, address, prices;

    public ViewHolder(View itemView) {
        super(itemView);
        mainImageview = (ImageView) itemView.findViewById(R.id.placeImage);
        placeNameHolder = (LinearLayout) itemView.findViewById(R.id.placeNameHolder);
        mainHolder = (LinearLayout) itemView.findViewById(R.id.mainHolder);
        homeTextView = (TextView) itemView.findViewById(R.id.placeName);
        address = (TextView) itemView.findViewById(R.id.propertyaddress);
        prices = (TextView) itemView.findViewById(R.id.priceid);
        mainHolder.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {


        if (itemClickListener != null) {

            itemClickListener.onItemClick(itemView, getPosition());
        }
    }
}

public interface onItemClickListener {

    void onItemClick(View v, int position);
}

public void setOnItemClickListener(final onItemClickListener itemClickListener) {
    this.itemClickListener = itemClickListener;

}

这是我的片段

    //oclick listener for the recylerview in the fragment
MainAdaptor.onItemClickListener OnItemClickListener = new MainAdaptor.onItemClickListener(){

    @Override
    public void onItemClick(View v, int position) {

        Intent intent = new Intent(getContext(),Details.class);
        intent.putExtra(Details.EXTRA_PARAM_ID,position);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
    }
};

我想这样做,当点击recyclerview项目时,活动图像视图

1 个答案:

答案 0 :(得分:1)

RecyclerView中添加此代码

   //Convert to byte array
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
  byte[] byteArray = stream.toByteArray();

  Intent intent = new Intent(v.getContext(), act.class);
  intent.putExtra("Image", byteArray /*byte[]*/);
  //View v
  v.getContext().startActivity(intent);

并在第二个添加:

byte[] byteArray = getIntent().getByteArrayExtra("image");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
imageview.setImageBitmap(bmp);
//or whatever

但似乎你在RecyclerView中有路径(字符串),在这种情况下,在RecyclerView

中添加这行代码
Intent intent = new Intent(v.getContext(), Activity.class);
intent.putExtra("Image", Image);
v.getContext().startActivity(intent);

在第二个活动中添加此

String UrlImage = getIntent().getSerializableExtra("Image");

final ImageView Header = (ImageView) findViewById(R.id.header);
Picasso.with(getApplicationContext())
                .load(UrlImage)
                .error(RandomClass.HeaderImage())
                .into(Header);