I want to set the background of a view from a string URL. I used this code to set an image from drawable:
View rightv = row.findViewById(R.id.four);
rightv.setBackgroundResource(R.drawable.demoimage);
rightv.setTag(position);
rightv.setOnClickListener(MembersDealActivity_a.this);
But when I tried to do the same from the URL, it did not work. I tried this sort of code too, but it did not work either:
Drawable res = getResources().getDrawable(imageResource);
right.setBackgroundDrawable(res);
right.setTag(position);
right.setOnClickListener(MembersDealActivity_a.this);
I also have tried to use the Picasso library, but when it request to set a value into parameter view it can't be cast there.
Picasso.with(this)
.load(imag_link).resize(600, 350)
.into(imv);
The full code:
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;
}
};