我正尝试使用以下代码通过URl访问图像:
public class SingleListItem extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.details_list);
TextView txtProduct = (TextView) findViewById(R.id.name);
TextView txtLdesc = (TextView) findViewById(R.id.longdesc);
SmartImageView imgPreview = (SmartImageView) findViewById(R.id.preview);
imgPreview.setImageUrl(lpreview);
Intent i = getIntent();
// getting attached intent data
String product = i.getStringExtra("title");
String ldesc = i.getStringExtra("longdesc");
String lpreview = i.getStringExtra("preview");
// displaying selected product name
txtProduct.setText(product);
txtLdesc.setText(ldesc);
我从另一个活动传递“预览”值。这包含我想要从中获取图像的URL,但它与上一个活动中的用户选择不同。在imgPreview.setImageUrl
中,我想将其设置为字符串lpreview
,而不是对其进行硬编码。
答案 0 :(得分:0)
在初始化setContentView()
之前尝试使用getIntent值public class SingleListItem extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
// getting attached intent data
String product = i.getStringExtra("title");
String ldesc = i.getStringExtra("longdesc");
String lpreview = i.getStringExtra("preview");
this.setContentView(R.layout.details_list);
TextView txtProduct = (TextView) findViewById(R.id.name);
TextView txtLdesc = (TextView) findViewById(R.id.longdesc);
SmartImageView imgPreview = (SmartImageView) findViewById(R.id.preview);
imgPreview.setImageUrl(lpreview);
// displaying selected product name
txtProduct.setText(product);
txtLdesc.setText(ldesc);