显示在列表视图
图像URL我是新来的Android域..显示在列表视图
我与小应用程序的工作..
我需要的是?
我有一个数组列表中的视频网址和图像网址,它从数据库中作为json对象进行检索并存储在单独的数组中。我想这个数组列表的图像应该显示在列表视图与文本。
如何实现?请帮助我..
我已经通过谷歌去了,但我仍然没有明显的例子。请任何一个帮助我..
感谢很多提前...
public class act extends Activity { /** Called when the activity is first created. */ static String uri1="http://i3.ytimg.com/vi/bQaWsVQSLdY/default.jpg"; static String uri2="http://i4.ytimg.com/vi/cJQCniWQdno/mqdefault.jpg"; static String uri3="http://i1.ytimg.com/vi/D8dA4pE5hEY/mqdefault.jpg"; public static String[] urls={uri1,uri2,uri3}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView grd=(GridView)findViewById(R.id.gridView1); grd.setAdapter(new ImageAdapter(this)); grd.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent,View v,int pos,long id) { Toast.makeText(getBaseContext(),"pic"+(pos+1)+"select ",Toast.LENGTH_SHORT).show(); } }); } public class ImageAdapter extends BaseAdapter { private Context context; private int itemBackground; ImageAdapter(Context c) { context=c; TypedArray a=obtainStyledAttributes(R.styleable.Gallery1); itemBackground=a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground,0); a.recycle(); } public int getCount() { return urls.length; } public Object getItem(int pos) { return pos; } public long getItemId(int pos) { return pos; } public View getView(int pos,View cv,ViewGroup vg) { ImageView imageview=new ImageView(context); imageview.setImageResource(urls[pos]); imageview.setScaleType(ImageView.ScaleType.FIT_XY); imageview.setLayoutParams(new Gallery.LayoutParams(150,120)); imageview.setBackgroundResource(itemBackground); return imageview; } }
}
我尝试像this..i不能抽到图像...
ÿ ou无法直接设置,因为您正在尝试做,您首先需要下载图像, 存储位图,然后才将图像应用于您ImageView
。
检查这个问题:
How to set image button resource from web url in Android?
这个解决方案一样好:
编辑我的代码,你发布的答案与下载image..plz即时新的android..If ü编辑我会学习它...帮助我.. – 2013-04-30 07:25:17
帮我... PLZ我无法使用我的代码中的代码.. – 2013-04-30 07:39:19
@OneManArmy,我不会为你写代码两个原因:1.我没时间了。 2.如果我愿意,你将不会学到任何东西。你误解了这个网站的目的。我们在这里帮助你,而不是为你做你的工作。如果您现在有其他问题,请使用新代码更新您的问题,或者打开一个更相关的新问题。 – 2013-04-30 08:26:28
如果要求显示列表行的ImageView和TextView中的再试试概念的通用装载机。 链接:
这是一个不同的问题与产品总数赏金? http://stackoverflow.com/questions/16212883/images-url-are-not-displaying-in-grid – Nezam 2013-04-30 08:15:47