Jump to content
Minmoas

[Reslovido] Ir buscar uma imagem a galeria

Recommended Posts

Minmoas

Boas eu to a criar uma aplicaçao e preciso de carregar num botao, quando carrego nesse botao quero poder ir a galeria do telemovel e escolher a foto e fazer com que ela aparece numa listView alguem consegue ajudar ando nisto a 1 semana

ta ai o meu layout 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <Button
        android:text="fotografar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button1"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="5.0dp" />
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="match_parent"
        android:layout_height="100.0dp"
        android:id="@+id/foto"
        android:layout_marginBottom="5.0dp"
        android:layout_marginTop="5.0dp"
        android:layout_marginRight="5.0dp"
        android:layout_marginLeft="5.0dp" />
    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="299.5dp"
        android:id="@+id/autoCompleteTextView1"
        android:layout_marginBottom="5.0dp"
        android:layout_marginTop="5.0dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" />
    <Button
        android:text="Publicar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnPublicar"
        android:layout_marginBottom="10.0dp"
        android:layout_marginTop="5.0dp"
        android:layout_marginRight="5.0dp"
        android:layout_marginLeft="5.0dp" />
</LinearLayout>

aqui esta o c#:

sei que a coisas que estao erradas mas nao sei resolver 

namespace APP_Sport_Life
{
    [Activity(Label = "yourMotions", MainLauncher = false, Icon = "@drawable/Logo")]
    public class yourMOTIONS_publicar : Activity
    {
        private Image mListView;
        private BaseAdapter<Image> mAdapter;
        private List<Image> mContacts;
        private ImageView mSelectedPic;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.yourMotions_publicar);
            mListView = FindViewById<ImageView>(Resource.Id.foto);
            mContacts = new List<Image>();

            Action<ImageView> action = PicSelected;
            
            
            mAdapter = new Foto(this, Resource.Layout.yourMotions_publicar, mContacts, action);
            mListView.Imagem = mAdapter;
        }
        private void PicSelected(ImageView selectedPic)
        {
            mSelectedPic = selectedPic;
            Intent intent = new Intent();
            intent.SetType("image/");
            intent.SetAction(Intent.ActionGetContent);
            this.StartActivityForResult(Intent.CreateChooser(intent, "Selecioa a foto"), 0);
        }
       protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if(resultCode == Result.Ok)
            {
                Stream stream = ContentResolver.OpenInputStream(data.Data);
                mSelectedPic.SetImageBitmap(BitmapFactory.DecodeStream(stream));
            }
        }
        
    }
}
Edited by Minmoas
Concluido

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.