我想實現這樣的場景:如何通過自定義的參數進的onClick監聽
- 我得到我的圖片
- 我將它們添加到動態滾動型
- 爲每個圖像我想補充的OnClick聽衆,所以當我點擊的形象,我得到一個對話框,其中顯示了圖像全屏(基本上,類似的ThickBox在JQuery中)
我的代碼:
decodetByteFullSize = getImageFromApi();
decodedByte=scaleToFitWidth(decodetByteFullSize, photoScroll.getWidth());
String DESIREDTEXT = GetStringFromApi();
ImageView resultImage = new ImageView(this);
resultImage.setImageBitmap(decodedByte);
resultImage.setPadding(0, 0, 0, 10);
resultImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog imagePopup = new Dialog(MainActivity.this);
View view = getLayoutInflater().inflate(R.layout.image_layout, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(DESIREDTEXT);
ImageView iv = (ImageView)view.findViewById(R.id.tabsImage);
iv.setImageBitmap(decodetByteFullSize);
imagePopup.setContentView(view);
imagePopup.show();
}
});
photoScroll.addView(resultImage);
這個問題 - 如何將DESIRED TEXT
和decodetByteFullSize
參數傳遞給onClick事件,因爲它對每個圖像都是動態的而且不同的?
在此先感謝!
什麼是「DESIRED TEXT」?你從webservice獲得它? –
這是一個圖像描述,我從Web-Api獲得。我將編輯我的代碼,使其更清晰。 –