hey i followed a tutorial for taking pictures in an android studios project but my app crashes without any log errors. any help would be appreciated. also if anyone knows how add pictures from the gallery into the imageview that would be great.
public class MainActivity extends Activity {
Button bn;
int REQUEST_CODE = 1;
ImageView IMG;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bn = (Button) findViewById(R.id.bn);
IMG = (ImageView) findViewById(R.id.img);
bn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(i.resolveActivity(getPackageManager())!= null){
startActivityForResult(i,REQUEST_CODE);
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public void onActivityResult(int requestcode, int resultcode, Intent data){
if(requestcode == REQUEST_CODE && resultcode == RESULT_OK)
{
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
IMG.setImageBitmap(imageBitmap);
}
}
}
HI I suppose you are asking to take picture from gallery or Camera then you want to set that image to ImageView. If i am right then follow below code
private void openCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
String currentTimeStamp = dateFormat.format(new Date());
f = new File(android.os.Environment.getExternalStorageDirectory(), currentTimeStamp);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
}
private void openGallery() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select File"), REQUEST_GALLERY);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
try {
String click = f.getAbsolutePath();
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(User_Detail.KEY_ALBUM_IMAGE_PATH, click);
values.put(User_Detail.USER_ID, Utlity.user_id);
values.put(User_Detail.KEY_ID_ALBUM_REF, album_id);
long loginStat = db.insert(User_Detail.TABLE_4, null, values);
loadData(album_id);
} catch (Exception e) {
e.printStackTrace();
}
} else if (requestCode == 2) {
Uri selectedImage = data.getData();
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
picturePath = c.getString(columnIndex);
if (picturePath != null && picturePath.length() > 1) {
ContentValues va = new ContentValues();
} else {
}
SQLiteDatabase db = dbHelper.getWritableDatabase();
String image_path = picturePath;
ContentValues values = new ContentValues();
values.put(User_Detail.KEY_ALBUM_IMAGE_PATH, image_path);
values.put(User_Detail.USER_ID, Utlity.user_id);
values.put(User_Detail.KEY_ID_ALBUM_REF, album_id);
long loginStat = db.insert(User_Detail.TABLE_4, null, values);
loadData(album_id);
c.close();
Log.w("path of image from gallery......******************.........", picturePath + "");
}
}
}
Now You get The ImagePath of selectd Image or Captured Image. Now you need to set in your Image View then Crate a Adapter class which extends BaseAdapter and in that adapter class You can set this image by converting Imagepath to Bitmap
Related
i tried to set on imageview with original quality but the image get compressed.
please help me to set image in imageview with original quality.
ImageView imageView;
private static final int CAMERA_REQUEST = 1888;
Bitmap photo;
uploadImg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
if(data!=null) {
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
Try using glide, first in your gradle add dependency
compile 'com.github.bumptech.glide:glide.3.7.0'
And use this code to get capture images
values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, PICTURE_RESULT);
And then in onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICTURE_RESULT:
if (requestCode == PICTURE_RESULT)
if (resultCode == Activity.RESULT_OK) {
try {
thumbnail = MediaStore.Images.Media.getBitmap(
getContentResolver(), imageUri);
imgView.setImageBitmap(thumbnail);
imageurl = getRealPathFromURI(imageUri);
Imageview imageView = (ImageView) findViewById(R.id.image_view);
Glide.with(this).load(imageurl).into(imageView);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
And to get the path of image
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
I have a problem that is i take a photo i want to save it in internal storage. but i don't know how do make it.Who can suggest some solution ? thanks.
There is my code:
public class ThreeFragment extends Fragment {
private static final String TAG = ThreeFragment.class.getSimpleName();
private static int RESULT_LOAD_IMAGE = 1;
private static final int REQUEST_IMAGE_CAPTURE = 1;
View root;
GridView gridView;
String mCurrentPhotoPath;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
root = inflater.inflate(R.layout.fragment_three, container, false);
dolist();
return root;
}
public void dolist() {
gridView = (GridView) root.findViewById(R.id.gridview);
gridView.setAdapter(new ImageAdapter(getActivity()));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
openGallery();
break;
case 1:
takePhoto();
break;
case 2:
Log.d(TAG, "333333333333333333333");
break;
default:
break;
}
}
});
}
private void takePhoto() {
Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}
}
private String saveToInternalSorage(Bitmap bitmap) {
ContextWrapper cw = new ContextWrapper(getActivity());
File dic = cw.getDir("TEST", Context.MODE_PRIVATE);
File mypath = new File(dic, ".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return dic.getAbsolutePath();
}
public void openGallery() {
Intent i = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE) {
if (resultCode == Activity.RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
}
}
else if (requestCode == REQUEST_IMAGE_CAPTURE) {
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap bitmap = (Bitmap) extras.get("data");
saveToInternalSorage(bitmap);
// setPath(saveToInternalSorage(bitmap));
}
}
}
}
*Try This :
File mImageFile is path where you want to store you camera image file.
Uri tempURI = Uri.fromFile(mImageFile);
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, tempURI);
activity.startActivityForResult(i, CHOOSE_CAMERA_RESULT);
then in your onActivityResult
#Override
public void onActivityResultRAW(int requestCode, int resultCode, Intent data)
{
super.onActivityResultRAW(requestCode, resultCode, data);
switch(requestCode)
{
case CHOOSE_CAMERA_RESULT:
{
if (resultCode == RESULT_OK)
{
// here you image has been save to the path mImageFile.
Log.d("ImagePath", "Image saved to path : " + mImageFile.getAbsoultePath());
}
}
break;
}
}*
Try This:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri());
cameraIntent.putExtra("return-data", true);
mActPanelFragment.startActivityForResult(cameraIntent, ActivityConstantUtils.CAMERA_REQUEST);
// method
public Uri setImageUri() {
File file = new File(Environment.getExternalStorageDirectory().getPath(), ActivityConstantUtils.STORED_IMAGE_PATH+"/Images/WOMCamera");
if (!file.exists()) {
file.mkdirs();
}
ActivityConstantUtils.mCurrentPhotoPath = (file.getAbsolutePath() + "/"+"IMG_"+ System.currentTimeMillis() + ".jpg");
Uri imgUri = Uri.fromFile(new File(ActivityConstantUtils.mCurrentPhotoPath));
if (file.canWrite()) {
}
return imgUri;
}
After that write code for result:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ActivityConstantUtils.GALLERY_INTENT_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
String imagePath = getFilePath(data);
}
}
private String getFilePath(Intent data) {
String imagePath;
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imagePath = cursor.getString(columnIndex);
cursor.close();
return imagePath;
}
I'm new to android development. I am trying to create an app where when a user take a picture, it's path will be saved to the database. I am able to save and retrieve the image when it's from the gallery, But how do I save it if it's taken by camera?
Here's My Code
private void selectImage() {
final CharSequence[] items = { "Take Photo", "Choose from Library",
"Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(Student_Profile.this);
builder.setTitle("Add Photo");
builder.setItems(items, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment
.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
} else if (items[item].equals("Choose from Library")) {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, "Select File"),
0);
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
#Override
public void onActivityResult( int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK){
if (requestCode == 0) {
studentsDbAdapter.delete_Pic_byID(studID);
Uri targetUri = data.getData();
picture_location=getPath(targetUri);
// picture_location = targetUri.toString();
studentsDbAdapter.insertImagePath(studID ,picture_location);
showpic();
} }
else if (requestCode == 1) {
// How do I get The URI?
// I'm thinking that maybe if I can get the Uri
//from the new image I can save it like how I saved the image to my DB gallery style.
String pic_location=getPath(Uri);
studentsDbAdapter.insertImagePath(studID ,pic_location);
showpic();
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
#SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public void showpic() {
//LoginDataBaseAdapter db = studentsDbAdapter.open();
boolean emptytab = false;
boolean empty = studentsDbAdapter.checkPic(null, emptytab);
//Cursor cursor = loginDataBaseAdapter.fetchProfileImageFromDatabase();
if(empty==false)
{
String pathName = studentsDbAdapter.getImapath(studID);
File image = new File(pathName);
if(image.exists()){
ImageView imageView= (ImageView) findViewById(R.id.studpic);
imageView.setImageBitmap(BitmapFactory.decodeFile(image.getAbsolutePath()));
}
}
}
Try this. It may help you.
if (fromGallery) {
data.getData()); //get image data like this
} else {
bm = (Bitmap) data.getParcelableExtra("data");
}
I want to take photos from gallery and set it in my ImageView as well as I want to take photo from camera and set it into my same Image View.
I am very much stuck on this.
Can anyone help me?
Thanks.
You can handle your camera view click this way:
cameraImageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
}
});
Do this in your activity when you return after capturing image.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0)
{
if(data != null)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
photo = Bitmap.createScaledBitmap(photo, 80, 80, false);
imageView.setImageBitmap(photo);
}
else{
}
}
}
Get the open source code for gallery. Lookout onclick for the image selection. Launch your activity by setting the intent uri being genrated on th onclick .
In your application, get the intent data and get the real path from uri and then decode, set it as image view element .
private String getRealPathFromURI(Uri contentUri) {
int columnIndex = 0;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
try {
columnIndex = cursor.getColumnIndexOrThrow
(MediaStore.Images.Media.DATA);
} catch (Exception e) {
Toast.makeText(ImageEditor.this, "Exception in getRealPathFromURI",
Toast.LENGTH_SHORT).show();
finish();
return null;
}
cursor.moveToFirst();
return cursor.getString(columnIndex);
}
You must implement this code to take image from camera or gallery :
Take this variable :
AlertDialog dialog;
private static final int IMAGE_PICK = 1;
private static final int IMAGE_CAPTURE = 2;
private Bitmap profile_imageBitmap;
On Button click event :
if (v == btn_uploadPhoto) {
dialog.show();
}
Then in your activity's oncreate method :
final String[] items = new String[] { "Take from camera",
"Select from gallery" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Image");
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item == 0) {
path = "";
Intent intent = new Intent(
"android.media.action.IMAGE_CAPTURE");
File folder = new File(Environment
.getExternalStorageDirectory() + "/LoadImg");
if (!folder.exists()) {
folder.mkdir();
}
final Calendar c = Calendar.getInstance();
String new_Date = c.get(Calendar.DAY_OF_MONTH) + "-"
+ ((c.get(Calendar.MONTH)) + 1) + "-"
+ c.get(Calendar.YEAR) + " " + c.get(Calendar.HOUR)
+ "-" + c.get(Calendar.MINUTE) + "-"
+ c.get(Calendar.SECOND);
path = String.format(
Environment.getExternalStorageDirectory()
+ "/LoadImg/%s.png", "LoadImg(" + new_Date
+ ")");
File photo = new File(path);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
startActivityForResult(intent, 2);
} else { // pick from file
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, "Choose a Photo"),
IMAGE_PICK);
}
}
});
dialog = builder.create();
Now Out of Oncreate :
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == IMAGE_PICK
|| requestCode == IMAGE_CAPTURE) {
switch (requestCode) {
case IMAGE_PICK:
this.imageFromGallery(resultCode, data);
img_myProfile.setImageBitmap(null);
img_myProfile.setImageBitmap(setphoto);
break;
case IMAGE_CAPTURE:
this.imageFromGallery(resultCode, data);
img_myProfile.setImageBitmap(null);
img_myProfile.setImageBitmap(setphoto);
break;
default:
break;
}
}
}
private void imageFromGallery(int resultCode, Intent data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
profile_Path = cursor.getString(columnIndex);
cursor.close();
setphoto = BitmapFactory.decodeFile(profile_Path);
}
private void imageFromCamera(int resultCode, Intent data) {
updateImageView((Bitmap) data.getExtras().get("data"));
}
private void updateImageView(Bitmap newImage) {
setphoto = newImage.copy(Bitmap.Config.ARGB_8888, true);
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
I have an activity that retrieves images from the device's gallery and uploads to a service. Now, for optimisation purposes, I would like to avoid uploading images that are on Picasa an just store their ID or URL for later retrieval.
So my question is, how do I retrieve that information. My intent code is pasted below and retrieves the URI of the image.
Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_PICK);
startActivityForResult(galleryIntent, GALLERY_PIC_REQUEST);
I tried to look for the PICASA_ID (MediaStore.Images.Media.PICASA_ID), but by using the method above, it returns null. Any ideas?
Launch an ACTION_GET_CONTENT intent instead of an ACTION_PICK
Provide a MediaStore.EXTRA_OUTPUT extra with an URI to a temporary file.
Add this to your calling activity:
File yourFile;
Now use this code to get Intent:
yourFile = getFileStreamPath("yourTempFile");
yourFile.getParentFile().mkdirs();
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
galleryIntent .setType("image/*");
galleryIntent .putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(yourFile));
galleryIntent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
startActivityForResult(galleryIntent, GALLERY_PIC_REQUEST);
MAKE SURE THAT yourFile is created
Also in your calling activity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode){
case GALLERY_PIC_REQUEST:
File file = null;
Uri imageUri = data.getData();
if (imageUri == null || imageUri.toString().length() == 0) {
imageUri = Uri.fromFile(mTempFile);
file = mTempFile;
//this is the file you need! Check it
}
//if the file did not work we try alternative method
if (file == null) {
if (requestCode == 101 && data != null) {
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
//check this string to extract picasa id
}
}
break;
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if(cursor!=null)
{
int index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(index);
}
else return null;
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dir =new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/MyImages");
dir.mkdir();
filename = ("Image_" + String.valueOf(System.currentTimeMillis()) + ".poc");
}
protected Uri getTempFile()
{
File file = new File(dir,filename);
muri = Uri.fromFile(file);
return muri;
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add("Pick Image");
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
openOptionsChooseDialog();
return true;
}
private void openOptionsChooseDialog()
{
AlertDialog.Builder builder = new AlertDialog.Builder(AppActivity.this).setTitle("Select Image").setItems(items, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("image/*");
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempFile());
startActivityForResult(intent, SELECT_PICTURE);
}
});
final AlertDialog alert = builder.create();
alert.show();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case SELECT_PICTURE : if (resultCode == RESULT_OK)
{
filepath = muri.getPath();
Toast.makeText(this, filepath, Toast.LENGTH_SHORT).show();
//can do bla bla bla...
}
I have used the same approach and it woks.Hope It could help u too..