2016-08-02 9 views
0

これは私のアダプタクラスなので、onBindViewHolderメソッドです。
Picassoからロードされた画像をNextActivityに送信する方法をお探しです。RecyclerViewからPicasaを使用してImageViewへのnextActivityへの画像の送信

package adapters; 

import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.squareup.picasso.Picasso; 

import java.util.ArrayList; 
import java.util.List; 

import oerrride.we.huzykamz.ugentapp.CinemaViewHolders; 
import oerrride.we.huzykamz.ugentapp.ItemObjects; 
import oerrride.we.huzykamz.ugentapp.MovieScrollingActivity; 
import oerrride.we.huzykamz.ugentapp.NtindaCinemaViewHolders; 
import oerrride.we.huzykamz.ugentapp.R; 

/** 
    * Created by HUZY_KAMZ on 7/22/2016. 
*/ 
public class NtindaCinemaAdapter extends  RecyclerView.Adapter<NtindaCinemaViewHolders> { 
    private String url="http://10.0.2.2/UgandaEntertainment/Ntinda/NtindaPics/"; 
private List<ItemObjects> itemList = null; 
private Context context; 
public View root = null ; 


private ArrayList<ItemObjects> arraylist; 
public NtindaCinemaAdapter(Context context, List<ItemObjects> itemList) { 
    this.itemList = itemList; 
    this.context = context; 
} 

@Override 
public NtindaCinemaViewHolders onCreateViewHolder(ViewGroup parent, int viewType) { 

    View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.ntinda_cinema_list, parent,false); 
    NtindaCinemaViewHolders rcv = new NtindaCinemaViewHolders(layoutView,context); 
    return rcv; 
} 

@Override 
public void onBindViewHolder(NtindaCinemaViewHolders holder, final int position) { 
    final ItemObjects feedItem = itemList.get(position); 
     holder.root.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 


       Intent intent = new Intent(NtindaCinemaAdapter.this.context, MovieScrollingActivity.class); 
       intent.putExtra(NtindaCinemaViewHolders.KEY_SYNOPSIS, feedItem.getSynopsis()); 
       intent.putExtra(NtindaCinemaViewHolders.KEY_MOVIE_IMAGE, feedItem.getPhoto()+url); 

       context.startActivity(intent); 
      } 
     }); 



    //Download image using picasso library 

    Picasso.with(context).load(url+feedItem.getPhoto()) 
      .error(R.drawable.placeholder). 
      resize(500,500) 
      .placeholder(R.drawable.placeholder) 

      .into(holder.moviepic); 

    holder.moviename.setText(itemList.get(position).getMovieName()); 

} 

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

これは私のnextActivityあり、そしてどのように私はここに

package oerrride.we.huzykamz.ugentapp; 

import android.content.Intent; 
import android.os.Bundle; 

import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.ImageView; 
import android.widget.TextView; 
import com.squareup.picasso.Picasso; 

public class MovieScrollingActivity extends AppCompatActivity { 

    TextView  synpsis_txt; 
    ImageView image; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_scrolling); 

     getSupportActionBar().setDisplayShowHomeEnabled(false); 
     android.support.v7.app.ActionBar actionBar = getSupportActionBar(); 
     actionBar.setDisplayHomeAsUpEnabled(true); 
     actionBar.hide(); 

// declarations 
     Intent getImage = getIntent(); 
     String gettingImageUrl = getImage.getStringExtra(NtindaCinemaViewHolders.KEY_MOVIE_IMAGE); 
     synpsis_txt = (TextView) findViewById(R.id.synopsis_txt); 
     image = (ImageView) findViewById(R.id.image_movie_scroll); 

     Bundle bundle = getIntent().getExtras(); 
     synpsis_txt.setText(bundle.getString(NtindaCinemaViewHolders.KEY_SYNOPSIS)); 
     Picasso.with(MovieScrollingActivity.this).load(gettingImageUrl).error(R.drawable.placeholder). 
       resize(500,500) 
       .placeholder(R.drawable.placeholder).into(image); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab2); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 

    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 
それを扱うことができる
+0

あなたは私に助けてくれますか? –

答えて

0

あり、それを行うにはいくつかの方法があるが、私のプロジェクトで、私はこの方法を使用しています:

の初すべてBitmapImageViewから取得し、base64Stringに変換し、StringからIntentを渡します。

あなたはそのようにそれを達成することができます:

Bitmap attachedbitmap= ((BitmapDrawable) imageview.getDrawable()).getBitmap(); 
Intent nextIntent=new Intent(this,SecondActivity.class); 
nextIntent.putExtra("image",encodeTobase64(attachedbitmap)); 

あなたのデコードおよびエンコード方法:SecondActivityで

public static String encodeTobase64(Bitmap image) { 
    Bitmap immagex=image; 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    immagex.compress(Bitmap.CompressFormat.JPEG, 90, baos); 
    byte[] b = baos.toByteArray(); 
    String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT); 
    // Log.e("LOOK", imageEncoded); 
    return imageEncoded; 
} 

public static Bitmap decodeBase64(String input) { 
    byte[] decodedByte = Base64.decode(input, 0); 
    return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); 
} 

Bundle extras=getIntent().getExtras(); 
String imageString=extras.getString("image"); 
Bitmap incomingBitmap=decodeBase64(imageString); 

@Editあなたのコメントにについて:

holder.root.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Intent intent = new Intent(NtindaCinemaAdapter.this.context, MovieScrollingActivity.class); 
     Bitmap attachedbitmap= ((BitmapDrawable) holder.moviepic.getDrawable()).getBitmap(); 
     intent.putExtra("image",encodeTobase64(attachedbitmap)); 
    } 
}); 
+0

今、私はそれを接続したり、ピカソに実装したりできますか? 'onBindViewHolder'メソッドで、@ YasinKacmaz –

+0

@huxaiphaerIdrisまだ質問がある場合は、私の答えを編集しました、それを聞いてください! –

+0

@ YasinKaçmaz、ビットマップ上のholder.movi​​epicの所有者にアクセスできません、 –

関連する問題