9
I’m looking for the image in Sdcard. It happens all right, open the gallery, select the image, but the selected image does not appear in Imageview.
Code:
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:
<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>
Could you put your layout in question? My suggestion is that your
ImageView
is not set in sizepx|dp|dpi|etc...
. If you cannot set, use the attributeadjustViewBounds
to theImageView
adjust the size according to the size of Bitmap.– Wakim
Posted below. @Wakim
– Isabella Julia
@Isabella Julia but managed to get the image?
– FlipNovid