hi thanks for your reply ...but i guess i need to explain more about my problem cause the funda you gave me didn't work or i guess i applied it wrongly...
my main problem is image sending between two activities.
i am sending you the query in detail and with code.
My first Activity is "Window_to_call". It shows a button (and it also has a blank imageViewer), when the button is clicked it starts second activity "Maker". Maker shows a gallery. What i want is when i click on any image of the gallery, window of Maker should close and the clicked image should appear in the imageViewer of "Window_to_call" .
I am sending you code of both the activities.
Window_to_call.java code:
- Code: Select all
package make.gallery;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Window_to_call extends Activity {
ImageView returnpic;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
returnpic = (ImageView) findViewById(R.id.ImageView01);
Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), Maker.class);
startActivityForResult(intent, 0);
Bitmap bm = intent.getParcelableExtra("bitmap");
returnpic.setImageBitmap(bm);
}
});
}
}
Maker.java code:
- Code: Select all
package make.gallery;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.AdapterView.OnItemClickListener;
import android.view.View;
import android.view.ViewGroup;
public class Maker extends Activity {
Gallery g;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(Maker.this, "" + position, Toast.LENGTH_SHORT).show();
Bitmap bm= BitmapFactory.decodeResource(getResources(),g.getSelectedItemPosition());
Intent intent = new Intent(Maker.this, Window_to_call.class);
intent.putExtra("bitmap", bm );
setResult(RESULT_OK, intent);
startActivity(intent);
finish();
}
});
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Maker);
mGalleryItemBackground = a.getResourceId(
R.styleable.Maker_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
I don't know where i am committing mistakes and whether my strategy is wrong for sending images.
plz help me...i have been fighting with this problem for more than a week.