WEB开发网
开发学院手机开发Android 开发 Android 开发之 GridView 网格布局使用 阅读

Android 开发之 GridView 网格布局使用

 2010-04-12 19:07:00 来源:WEB开发网   
核心提示:2. 自定义 class ImageList extends BaseAdapter 其中主要是:写道View getView(int position, View convertView, ViewGroup parent)用于显示目标ImageViewJava代码1. public class ImageList

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

Tags:Android 开发 GridView

编辑录入:coldstar [复制链接] [打 印]
赞助商链接