Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
tags editadas
Link
ramaral
  • 44,7mil
  • 14
  • 60
  • 110

Estou buscando a imagem no SdCard. Acontece tudo certinho, abre a galeria, seleciona a imagem, mas a imagem selecionada não aparece no ImageView!.

Código:

 public void btnFoto(View view){
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(intent, IMAGEM_INTERNA);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    if(requestCode == IMAGEM_INTERNA){

        if(resultCode == RESULT_OK){
            Uri imagemSelecionada = intent.getData();

            String[] colunas = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(imagemSelecionada, colunas, null, null, null);
            cursor.moveToFirst();

            int indexColuna = cursor.getColumnIndex(colunas[0]);
            String pathImg = cursor.getString(indexColuna);
            cursor.close();

            Bitmap bitmap = BitmapFactory.decodeFile(pathImg);
            ImageView iv = (ImageView) findViewById(R.id.imgEvento);
            iv.setImageBitmap(bitmap);
        }
    }

-------------------- LAYOUT -----------------------------------------Layout:

Estou buscando a imagem no SdCard. Acontece tudo certinho, abre a galeria, seleciona a imagem, mas a imagem selecionada não aparece no ImageView!

 public void btnFoto(View view){
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(intent, IMAGEM_INTERNA);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    if(requestCode == IMAGEM_INTERNA){

        if(resultCode == RESULT_OK){
            Uri imagemSelecionada = intent.getData();

            String[] colunas = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(imagemSelecionada, colunas, null, null, null);
            cursor.moveToFirst();

            int indexColuna = cursor.getColumnIndex(colunas[0]);
            String pathImg = cursor.getString(indexColuna);
            cursor.close();

            Bitmap bitmap = BitmapFactory.decodeFile(pathImg);
            ImageView iv = (ImageView) findViewById(R.id.imgEvento);
            iv.setImageBitmap(bitmap);
        }
    }

-------------------- LAYOUT -----------------------------------------

Estou buscando a imagem no SdCard. Acontece tudo certinho, abre a galeria, seleciona a imagem, mas a imagem selecionada não aparece no ImageView.

Código:

public void btnFoto(View view){
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(intent, IMAGEM_INTERNA);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    if(requestCode == IMAGEM_INTERNA){

        if(resultCode == RESULT_OK){
            Uri imagemSelecionada = intent.getData();

            String[] colunas = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(imagemSelecionada, colunas, null, null, null);
            cursor.moveToFirst();

            int indexColuna = cursor.getColumnIndex(colunas[0]);
            String pathImg = cursor.getString(indexColuna);
            cursor.close();

            Bitmap bitmap = BitmapFactory.decodeFile(pathImg);
            ImageView iv = (ImageView) findViewById(R.id.imgEvento);
            iv.setImageBitmap(bitmap);
        }
    }

Layout:

adicionou 4766 caracteres ao conteúdo
Fonte Link

-------------------- LAYOUT -----------------------------------------

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Cadastro de Evento"
    android:id="@+id/textView2"
    android:layout_gravity="center_horizontal"
    style="@style/estilo"
    android:layout_marginBottom="25dp"
    android:textStyle="bold" />

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Título"
    android:id="@+id/txtTitulo" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtTitulo"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Descrição"
    android:id="@+id/txtDescricao" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtDescricao"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Data"
    android:id="@+id/txtData" />

<EditText
    android:layout_width="190dp"
    android:layout_height="wrap_content"
    android:inputType="date"
    android:ems="10"
    android:id="@+id/edtData"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Horário"
    android:id="@+id/txtHorario" />

<EditText
    android:layout_width="190dp"
    android:layout_height="wrap_content"
    android:inputType="time"
    android:ems="10"
    android:id="@+id/edtHorario"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Local"
    android:id="@+id/txtLocal" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtLocal"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Pontos de venda"
    android:id="@+id/textView3" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtPontoVenda"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"
    android:layout_marginBottom="15dp"/>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right">

    <Button
    android:id="@+id/btnFoto"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:layout_marginLeft="20dp"
    android:text="Foto"
    android:textColor="#FFF"
    android:textSize="10dp"
    android:drawableLeft="@drawable/ic_save"
    android:background="@drawable/botao"
    android:layout_gravity="right"
    android:onClick="btnFoto"/>

    <Button
        android:id="@+id/btnSalvar"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_marginLeft="20dp"
        android:text="  Salvar"
        android:textColor="#FFF"
        android:textSize="10dp"
        android:drawableLeft="@drawable/ic_save"
        android:background="@drawable/botao" />

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/imgEvento" />
</TableRow>

-------------------- LAYOUT -----------------------------------------

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Cadastro de Evento"
    android:id="@+id/textView2"
    android:layout_gravity="center_horizontal"
    style="@style/estilo"
    android:layout_marginBottom="25dp"
    android:textStyle="bold" />

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Título"
    android:id="@+id/txtTitulo" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtTitulo"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Descrição"
    android:id="@+id/txtDescricao" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtDescricao"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Data"
    android:id="@+id/txtData" />

<EditText
    android:layout_width="190dp"
    android:layout_height="wrap_content"
    android:inputType="date"
    android:ems="10"
    android:id="@+id/edtData"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Horário"
    android:id="@+id/txtHorario" />

<EditText
    android:layout_width="190dp"
    android:layout_height="wrap_content"
    android:inputType="time"
    android:ems="10"
    android:id="@+id/edtHorario"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Local"
    android:id="@+id/txtLocal" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtLocal"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"/>

<TextView
    style="@style/estilo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Pontos de venda"
    android:id="@+id/textView3" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/edtPontoVenda"
    style="@style/comprimento"
    android:background="@drawable/bordas_edit"
    android:layout_marginBottom="15dp"/>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right">

    <Button
    android:id="@+id/btnFoto"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:layout_marginLeft="20dp"
    android:text="Foto"
    android:textColor="#FFF"
    android:textSize="10dp"
    android:drawableLeft="@drawable/ic_save"
    android:background="@drawable/botao"
    android:layout_gravity="right"
    android:onClick="btnFoto"/>

    <Button
        android:id="@+id/btnSalvar"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_marginLeft="20dp"
        android:text="  Salvar"
        android:textColor="#FFF"
        android:textSize="10dp"
        android:drawableLeft="@drawable/ic_save"
        android:background="@drawable/botao" />

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/imgEvento" />
</TableRow>
Fonte Link
Carregando
1
2