我有一个字符串数组,其中包含图像URL和文本,我在图像视图中显示文本。在这里我想要当用户点击imageview我想获得该图像并将在android活动中显示。我怎么能这样做
代码: -
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);
答案 0 :(得分:0)
我不确定你的要求。如果您想要传递图像数据,请参考代码。
发送活动
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);
}
答案 1 :(得分:0)
将图像变量存储为静态并从中获取单击位置 String [] arr = new String [] {..}。只是将点击的位置传递给另一个活动并使用getIntent()获取位置和firstactivity.arr [pos]然后你将得到url。
实施例: 活动1: public static String [] arr = new String [] {..} 意图 - >传递位置(点击位置) 活动2: POS = getintent()getIntExtra(K,V);
现在获取网址: Activity1.arr [POS];