![](/img/trans.png)
[英]I have taken image from gallery to image view in same intent.And on image view click I want to send that image another Activity through intent.
[英]How to click image view and send that image in another activity through intent?
如何使用ClickListener單擊圖像視圖以及如何通過意圖將圖像發送或傳遞到另一個活動
imgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
我不知道編碼,因為我是Android新手
嘗試這個....
imageview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this,HomeActivity.class);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
i.putExtra("bmp_img", bmp);
startActivity(i);
然后在第二項活動中
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("Bitmap");
imageView.setImageBitmap(bitmap);
嘗試下面的代碼。
將其寫在您的FirstActivity.java中
imgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent mIntent = new Intent(this, ActivityTwo.class);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
mIntent.putExtra("bmp_img", bmp);
startActivity(mIntent);
}
});
這是在SecondActivity.java中
在您的XML中拍攝一張圖片,然后在onCreate方法中傳遞此代碼
Bitmap mBitmap = (Bitmap) intent.getParcelableExtra("bmp_img");
imageview.setImageResource(mBitmap);
將此R.drawable.ic_launcher
替換為您要傳遞的任何圖像。
1)如何點擊圖片查看
ImageView img = (ImageView) findViewById(R.id.myImageId);
img.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// your code here
}
});
2)如何通過意圖在另一個活動中發送該圖像
在第一次活動。
Intent currentIntent = new Intent(MainActivity.this, ActivitySecond.class);
currentIntent .putExtra("bmp_img", bmp);
startActivity(currentIntent );
為了在第二活動中獲得輸出,
在第二活動中。
Bitmap mBitmap = (Bitmap) intent.getParcelableExtra("bmp_img");
最后你可以這樣寫
ImageView img = (ImageView) findViewById(R.id.myImageId);
img .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent currentIntent = new Intent(MainActivity.this, ActivitySecond.class);
//suppose your image is simple icon launcher
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
currentIntent .putExtra("bmp_img", bmp);
startActivity(currentIntent );
}
});
現在正在進行第二活動
ImageView imageview= (ImageView) findViewById(R.id.yourImageId);
Bitmap mBitmap = (Bitmap) intent.getParcelableExtra("bmp_img");
imageview.setImageResource(mBitmap);
imgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myIntent=new Intent(ThisView.this,NextView.class);
Bundle i = new Bundle();
i.putByte("Image", yourImage);
myIntent.putExtras(i);
startActivity(myIntent);
}
});
使用以下代碼。
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
intent.putExtras(extras);
startActivity(intent);
}
});
在下面的另一個活動調用llike中。
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
image.setImageBitmap(bmp );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.