Android 开发之 GridView 网格布局使用
2010-04-12 19:07:00 来源:WEB开发网2. 自定义 class ImageList extends BaseAdapter 其中主要是:
写道
View getView(int position, View convertView, ViewGroup parent)
用于显示目标ImageView
Java代码
1. public class ImageList extends BaseAdapter {
2. Activity activity;
3.
4. //construct
5. public ImageList(Activity a ) {
6. activity = a;
7. }
8.
9. @Override
10. public int getCount() {
11. // TODO Auto-generated method stub
12. return image.length;
13. }
14.
15. @Override
16. public Object getItem(int position) {
17. // TODO Auto-generated method stub
18. return image[position];
19. }
20.
21. @Override
22. public long getItemId(int position) {
23. // TODO Auto-generated method stub
24. return position;
25. }
26.
27. @Override
28. public View getView(int position, View convertView, ViewGroup parent) {
29. // TODO Auto-generated method stub
30. ImageView iv = new ImageView(activity);
31. iv.setImageResource(image[position]);
32. return iv;
33. }
34. }
public class ImageList extends BaseAdapter {
Activity activity;
//construct
public ImageList(Activity a ) {
activity = a;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return image.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return image[position];
更多精彩
赞助商链接