我想从字符串 URL 设置视图的背景。我使用此代码从可绘制对象中设置图像:
View rightv = row.findViewById(R.id.four);
rightv.setBackgroundResource(R.drawable.demoimage);
rightv.setTag(position);
rightv.setOnClickListener(MembersDealActivity_a.this);
但是,当我尝试从 URL 执行相同操作时,它不起作用。我也尝试过这种代码,但它也不起作用:
Drawable res = getResources().getDrawable(imageResource);
right.setBackgroundDrawable(res);
right.setTag(position);
right.setOnClickListener(MembersDealActivity_a.this);
我也尝试过使用 Picasso 库,但是当它请求将值设置到参数视图中时,它不能在那里转换。
Picasso.with(this)
.load(imag_link).resize(600, 350)
.into(imv);
完整代码:
public class MyActivity extends Activity implements
AdapterView.OnItemClickListener, View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView list = new ListView(this);
setContentView(list);
String[] items = { "Tom", "Sally", "Bill", "John", "Santiago",
"Isabella" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.review, R.id.textView1, items) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
View text = row.findViewById(R.id.seemore);
text.setTag(position);
text.setOnClickListener(MyActivity.this);
View left = row.findViewById(R.id.imageView1);
left.setBackgroundResource(R.drawable.newapture);
left.setTag(position);
left.setOnClickListener(MyActivity.this);
return row;
}
};