gpt4 book ai didi

java - Android java从字符串访问URL而不是硬编码

转载 作者:行者123 更新时间:2023-12-01 04:46:41 26 4
gpt4 key购买 nike

我尝试使用以下代码通过 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);

我正在传递另一个 Activity 的“预览”值。其中包含我想要从中抓取图像的 URL,但它与上一个 Activity 中的用户选择不同。在 imgPreview.setImageUrl 中,我想将其设置为字符串 lpreview,而不是对其进行硬编码。

最佳答案

尝试一下,在初始化 setContentView() 之前获取 Intent 值

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);

关于java - Android java从字符串访问URL而不是硬编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15715270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com