我正在尝试在我的活动中显示图像和一些字符串,但由于某种原因,视图没有被修改。
这是我的代码:
import java.io.File;
import java.io.FileInputStream;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;
public class ObjectProperty extends Activity {
Activity myAct = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
myAct = this;
setContentView(R.layout.object_property);
String objetoNome = myAct.getIntent().getStringExtra("nome");
String arquivo = myAct.getIntent().getStringExtra("arquivo");
String descricao = myAct.getIntent().getStringExtra("descricaoCompleta");
System.out.println("objeto nome: " + objetoNome); //not null/empty
System.out.println("arquivo: " + arquivo); //not null/empty
System.out.println("descricao: " + descricao); //not null/empty
ImageView imageView = (ImageView)findViewById(R.id.item_image);
TextView textViewNome = (TextView)findViewById(R.id.item_nome);
TextView textViewDescricao = (TextView)findViewById(R.id.item_desc);
textViewNome.setText(objetoNome); //does not set text
textViewDescricao.setText(descricao); //does not set text
if(!arquivo.equals("")){
Bitmap myBit = getThumbnail(arquivo);
if(myBit != null)
imageView.setImageBitmap(myBit); // does not set image
}
super.onCreate(savedInstanceState);
setContentView(R.layout.object_property);
}
public Bitmap getThumbnail(String filename)
{
Bitmap thumbnail = null;
try {
File filePath = myAct.getFileStreamPath(filename);
FileInputStream fi = new FileInputStream(filePath);
thumbnail = BitmapFactory.decodeStream(fi);
} catch (Exception ex) {
ex.printStackTrace();
}
return thumbnail;
}
}
我究竟做错了什么?