How to add images to the grid view and adding click function to these images?

百般思念 提交于 2020-01-03 04:32:28

问题


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);
    }
}

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..


回答1:


try 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 );


来源:https://stackoverflow.com/questions/17420248/how-to-add-images-to-the-grid-view-and-adding-click-function-to-these-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!