如何将图像添加到网格视图和增加点击功能,这些图片? [英] How to add images to the grid view and adding click function to these images?

查看:126
本文介绍了如何将图像添加到网格视图和增加点击功能,这些图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public final class gridFieldDemoScreen extends MainScreen
{
    LabelField one, two, three, four, five, six;
    public gridFieldDemoScreen()
    {
        setTitle("gridFieldDemo");   
        GridFieldManager grid = new GridFieldManager(2, 3, 0);
        one = new LabelField("ONE");
        grid.insert(one, 0);
        two = new LabelField("TWO");
        grid.insert(two , 1);
        three = new LabelField("THREE");
        grid.insert(three, 2);
        four = new LabelField("FOUR");
        grid.insert(four, 3);
        five = new LabelField("FIVE");
        grid.insert(five, 4);
        six = new LabelField("SIX");
        grid.insert(six, 5);
        grid.setColumnPadding(20);
        grid.setRowPadding(20);
        add(grid);
    }
}

我可以创建一个简单的GridView控件,现在我想的图像和增加点击功能添加到这些图像,plz帮助我这个..

I am able to create a simple gridview, now i want to add images and adding click function to these images, plz help me for this..

推荐答案

试试这个 -

GridFieldManager grid = new GridFieldManager(2,2,0); 
EncodedImage g1 = EncodedImage.getEncodedImageResource("image1.png");
EncodedImage g2 = EncodedImage.getEncodedImageResource("image2.png");
EncodedImage g3 = EncodedImage.getEncodedImageResource("image3.png");
EncodedImage g4 = EncodedImage.getEncodedImageResource("image4.png");

grid.add(new BitmapField(g1.getBitmap(),FOCUSABLE){
          protected boolean navigationClick(int status, int time){
                          //here your can add your code.
                return true;
            }

    });
grid.add(new BitmapField(g2.getBitmap(),FOCUSABLE){
              protected boolean navigationClick(int status, int time){
                              //here your can add your code.
                    return true;
                }

        });
grid.add(new BitmapField(g3.getBitmap(),FOCUSABLE){
              protected boolean navigationClick(int status, int time){
                              //here your can add your code.
                    return true;
                }

        });
grid.add(new BitmapField(g4.getBitmap(),FOCUSABLE){
              protected boolean navigationClick(int status, int time){
                              //here your can add your code.
                    return true;
                }

        });



 add(grid );

这篇关于如何将图像添加到网格视图和增加点击功能,这些图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆