2016-05-18 86 views
0

我想從我的ercyclerview片段發送一個圖像到活動現在我不知道如何做到這一點。新手()。 這是我的適配器發送btimap到另一個活動

@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產品進入活動的ImageView

回答

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); 

並在第二個o NE補充一點:

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); 
+0

在哪裏如果您的意思是'getIntent'部分只是將其添加到第二個Activity中,那麼我會將第二個代碼片段放在recyclerview – droid501

+0

中嗎?或者您的意思是'Intent' ** S tring **只是創建路徑變量('私人字符串路徑;')並把'意圖'你有'ClickListener'像'onItemClick'和'請更清楚你的問題' – Hosseini

+0

謝謝你,我設法了它,我我在Android新,所以有時我的問題有點抽象,我會嘗試更具體。再次感謝 – droid501

相關問題