2016-11-17 7 views
0

私は画像のURLとテキストを含む文字列の配列を持っています。これはテキスト付きの画像ビューで表示しています。画像をクリックしてその画像をアンドロイドの別のアクティビティに表示するにはどうすればいいですか?

ImageView m_DealImage;String[] dealText = {"Install Medlife", "Install Voonik", "Install IndigoRummy","Install Chai point"}; 

String[] arr = new String[]{ 
     "http://media.vcommission.com/brand/files/vcm/3012/Medlife_CPS_MLVC2_336X280.jpg", 
     "http://media.vcommission.com/brand/files/vcm/3156/Voonik_CPS_Half_Price_Fashion_Sale_728x90.jpg", 
     "http://media.vcommission.com/brand/files/vcm/3144/IndigoRummy_CPA_starter_banus_100_728x90.gif"}; 

/*First Step*/ 
         handler = new Handler(); 
         Runnable runnable = new Runnable() { 
          int i =0; 
          @Override 
          public void run() { 
           Picasso.with(getApplicationContext()).load(arr[i]).into(m_DealImage); 
           m_ToolTip.setVisibility(View.VISIBLE); 
           m_DealText.setText(dealText[i]); 
           i++; 
           if (i > arr.length - 1) { 
            i = 0; 
           } 
           m_DealImage.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View v) { 
             // Didn't know where to go 
            } 
           }); 
           handler.postDelayed(this, 6000); 
          } 
         }; 
         handler.postDelayed(runnable, 6000); 
+2

インテント・エクストラを使用して、次のアクティビティに必要なURLを渡します。これを行う方法は次のとおりです。http://stackoverflow.com/questions/5265913/how-to-use-putextra-and-getextra-for-string-data –

答えて

0

私は何をお使いの提示を確認していない - :ユーザクリックImageViewのiがその画像を取得したいとAndroid activity.Howに表示されます私が行うことができたときに、ここで私は

コードがいることを望みます。画像データを渡す場合は、コードを参照してください。

送信アクティビティ

Intent _intent = new Intent(this, newscreen.class); 
Bitmap _bitmap; // your bitmap 
ByteArrayOutputStream _bs = new ByteArrayOutputStream(); 
_bitmap.compress(Bitmap.CompressFormat.PNG, 50, _bs); 
i.putExtra("byteArray", _bs.toByteArray()); 
startActivity(i); 

活性

if(getIntent().hasExtra("byteArray")) { 
ImageView _imv= new ImageView(this); 
Bitmap _bitmap = BitmapFactory.decodeByteArray(
     getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);   
_imv.setImageBitmap(_bitmap); 
} 
0

ストア画像可変静的及び のString [] ARR =新しいString [] {..}からクリックされた位置を取得する受信。クリックした位置を別のアクティビティに渡し、getIntent()を使用してpositionとfirstactivity.arr [pos]を取得すると、URLが取得されます。

例: 活性1: パブリック静的文字列[] ARR =新しいString [] {..} 意図 - >パスの位置(クリック位置) 活動2: POS = getintent()getIntExtra(K。 、v)。

今すぐURLを取得: Activity1.arr [pos];

+0

参考のためにコードを入力してください – Ravi

+0

public static String [] arr =新しいString [] { "http://media.vcommission.com/brand/files/vcm/3012/Medlife_CPS_MLVC2_336X280.jpg"、 }。 Picasso.with(getApplicationContext())(ARR [0])に負荷(m_DealImage)。 m_DealImage.setOnClickListener(新View.OnClickListener(){@Override ます。public void onClickの(ビューV){ startActivity(新しいテント(MainActivity.this、Main2Activity.class).putExtra( "POS"、1)); } }); – Vadivel

+0

Activity2:ImageViewの=(ImageViewの)findViewById(R.id.imageView)。 int型のPOS = getIntent()getIntExtra( "POS"、1)。 Picasso.with(getApplicationContext())負荷(MainActivity.arr [POS])(ImageViewの)へ。。。 – Vadivel

関連する問題