1

我正在尝试使用以下代码通过 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中,我想将其设置为 string lpreview,而不是对其进行硬编码。

4

1 回答 1

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);
于 2013-03-30T05:25:02.930 回答