2016-05-21 3 views
1

FirstActivityから選択された複数の画像を送信し、それをSecondActivityに送信したい場合は、onCreateメソッド(FirstActivity) setAdapterをphotoAdapterとして設定します。ボタンで複数の画像を1つのアクティビティから2番目のアクティビティ、Recyclerviewで選択して送信

 recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 
     recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL)); 
     photoAdapter = new PhotoAdapter(this, selectedPhotos); 
     recyclerView.setAdapter(photoAdapter); 

とのonClickメソッドは、私が

  newRecyclerView = (RecyclerView)findViewById(R.id.newRV); 
     newRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL)); 
     Intent new = getIntent(); 
     new.getExtra("ABCD"); 

プログラムがうまく動作していることを宣言し、SecondActivityに

 public void send(View v){ 
     Intent intent=new Intent(this, SecondActivity.class); 
     intent.putExtra("ABCD",selectedPhotos) 
     startActivity(intent); 
     } 

以下とOnCreateの方法としてSecondActivityに画像を渡すためにFirstActivityに送りますFirstActivity RecyclerViewに複数の画像が表示されますが、「送信」ボタンをクリックすると、SecondActivity RecyclerViewに送信される画像はありません。どうすればこの問題を解決できますか?

答えて

1

イメージ名またはIDのArraylistを送信できます。以下のような...

ArrayList<String> object = new ArrayList<String>(); //you can send image names or int resource id. 
Intent intent = new Intent(Current.class, NextActivity.class); 
Bundle args = new Bundle(); 
args.putSerializable("ARRAYLIST",(Serializable)object); 
intent.putExtra("BUNDLE",args); 
startActivity(intent); 

、次のActivityBundle

Intent intent = getIntent(); 
Bundle args = intent.getBundleExtra("BUNDLE"); 
ArrayList<String> object = (ArrayList<String>) args.getSerializable("ARRAYLIST"); 

はテストされていない取得しかし、あなたがしようとするすべての問題なら、私に知らせることができます。

+0

のArrayListすでに、私のインスタンス変数に宣言されている話をしている ArrayListのよう selectedPhotos =新しいArrayListを<>( );この「選択された写真」は第2のアクティビティには適用されません。 –

+0

あなたの答えをありがとう、多くの助け、私はついにそれを働かせます。ありがとう@Devendra –

0

FirstActivity onclickの方法

public void send(View v){ 
     Intent intent = new Intent(this,Confirmation.class); 
     Bundle args = new Bundle(); 
     args.putSerializable("ARRAYLIST", selectedPhotos); 
     intent.putExtra("BUNDLE",args); 

     startActivity(intent); 

    } 

そしてSecondActivityのonCreateメソッド

Intent intent = getIntent(); 
    Bundle args = intent.getBundleExtra("BUNDLE"); 
    selectedPhotos = (ArrayList<String>)args.getSerializable("ARRAYLIST"); 
    newRecyclerView=(RecyclerView)findViewById(R.id.recycler_view3); 
    photoAdapter=new PhotoAdapter(this,selectedPhotos); 
    newRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL)); 
    newRecyclerView.setAdapter(photoAdapter); 
関連する問題