本文介绍了ListField的方法无效不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个自定义列表领域,但它当我调用失效方法不会不工作。屏幕总是空的,而列表字段的数据不为空或空!
请帮我找出这个问题。

谢谢你在前进

公共类FileListField扩展ListField实现ListFieldCallback {    私有静态最后的位图fileBitmap = Bitmap.getBitma $ P $的PSource(document.png);
    私有静态最后的位图dirBitmap = Bitmap.getBitma $ P $的PSource(emty_folder.png);
    私有静态最后的位图addBitmap = Bitmap.getBitma $ P $的PSource(svn_added.png);
    私有静态最后的位图delBitmap = Bitmap.getBitma $ P $的PSource(svn_deleted.png);
    私有静态最后的位图modBitmap = Bitmap.getBitma $ P $的PSource(svn_modified.png);
    私有静态最后的位图novBitmap = Bitmap.getBitma $ P $的PSource(svn_noversion.png);
    私有静态最后的位图norBitmap = Bitmap.getBitma $ P $的PSource(svn_normal.png);
    //静态位图dowBitmap = Bitmap.getBitma $ P $的PSource(svn_added.png);    私人BigVector BV;    公共FileListField(){
        超();
        BV =新BigVector();
        setCallback(本);
    }    公共无效setFileModelVector(BigVector fileModelVector){
        bv.removeAll();
        bv.addElements(fileModelVector.getContiguousArray());
        无效();
        的System.out.println(ISSSSSSSSSSSSSS CALLLLLLLLLLINNNNNNNG?);
        的System.out.println(DISSSPATH?+ UiApplication.isEventDispatchThread());
// invalidateRange(0,bv.size() - 1);
// FileModel [] = fileModelArr新FileModel [fileModelVector.size()];
//的for(int i = 0; I< fileModelVector.size();我++)
// fileModelArr [I] =(FileModel)fileModelVector.elementAt(ⅰ);
//集(fileModelArr);
    }    公共BigVector getFileModelVector(){
// BigVector BV =新BigVector();
//的for(int i = 0; I< this.getSize();我++)
// bv.addElement(获得(这一点,我));
        BV的回报;
    }    公共无效集(对象[]或){    }    公共对象获取(ListField名单,INT指数){
        返回bv.elementAt(索引);
    }    公众诠释的getSize(){
        返回bv.size();
    }    公众诠释indexOfList(ListField listField,字符串preFIX,INT启动){
        返回getSelectedIndex();
    }    公众诠释的get preferredWidth(ListField listField){
        返回Display.getWidth();
    }    公共无效drawListRow(ListField listField,显卡显卡
            ,INT指数,诠释Y,int width)将{
        的System.out.println(DRWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA);
        FileModel fileModel =(FileModel)得到(listField,指数);
        如果(fileModel.isFile())
            graphics.drawBitmap(0,Y,宽度,fileBitmap.getHeight()
                    ,fileBitmap,0,0);
        其他
            graphics.drawBitmap(0,Y,宽度,dirBitmap.getHeight()
                    ,dirBitmap,0,0);
        开关(fileModel.getStatus()){
            案例FileModel.ADD_STATUS:
                graphics.drawBitmap(0,Y,宽度,addBitmap.getHeight()
                        ,addBitmap,0,0);
                打破;
            案例FileModel.DEL_STATUS:
                graphics.drawBitmap(0,Y,宽度,delBitmap.getHeight()
                        ,delBitmap,0,0);
                打破;
            案例FileModel.MOD_STATUS:
                graphics.drawBitmap(0,Y,宽度,modBitmap.getHeight()
                        ,modBitmap,0,0);
                打破;
            案例FileModel.DOW_STATUS:
                打破;
            案例FileModel.NOR_STATUS:
                graphics.drawBitmap(0,Y,宽度,norBitmap.getHeight()
                        ,norBitmap,0,0);
                打破;
            默认:
                graphics.drawBitmap(0,Y,宽度,novBitmap.getHeight()
                        ,novBitmap,0,0);
                打破;
        }
        graphics.drawText(fileModel.getName(),fileBitmap.getWidth()中,y);
    }}


解决方案
我不认为调用

无效() ListField 就足够了。在无效()呼叫真的是一个的方法,即表示该字段必须重新绘制。你真正做的是表明这另一个问题

试着改变你的code到这样的事情,使用的setSize()

 公共无效setFileModelVector(BigVector fileModelVector){
    bv.removeAll();
    bv.addElements(fileModelVector.getContiguousArray());
    //无效();
    的setSize(bv.size());
}

我也不知道你究竟是如何处理的载体本身的所有权,但你也很可能只是做到这一点:

 公共无效setFileModelVector(BigVector fileModelVector){
    BV = fileModelVector;
    //无效();
    的setSize(bv.size());
}

因为你清除出整个矢量,那么新的向量转换到一个数组,然后加入阵列的原始载体。但是,这是一个单独的问题,而不是你所看到的原因,一个空 ListField

I'm writing a custom list field, but it doesn't not work when i invoke invalidate method. The screen is always empty, while the data of list field is not null or empty!Please help me figure out the problem.
Thank you in advance

public class FileListField extends ListField implements ListFieldCallback{

    private static final Bitmap fileBitmap = Bitmap.getBitmapResource("document.png");
    private static final Bitmap dirBitmap = Bitmap.getBitmapResource("emty_folder.png");
    private static final Bitmap addBitmap = Bitmap.getBitmapResource("svn_added.png");
    private static final Bitmap delBitmap = Bitmap.getBitmapResource("svn_deleted.png");
    private static final Bitmap modBitmap = Bitmap.getBitmapResource("svn_modified.png");
    private static final Bitmap novBitmap = Bitmap.getBitmapResource("svn_noversion.png");
    private static final Bitmap norBitmap = Bitmap.getBitmapResource("svn_normal.png");
    //static Bitmap dowBitmap = Bitmap.getBitmapResource("svn_added.png");

    private BigVector bv;

    public FileListField(){
        super();
        bv = new BigVector();
        setCallback(this);
    }

    public void setFileModelVector(BigVector fileModelVector){
        bv.removeAll();
        bv.addElements(fileModelVector.getContiguousArray());
        invalidate();
        System.out.println("ISSSSSSSSSSSSSS CALLLLLLLLLLINNNNNNNG?");
        System.out.println("DISSSPATH?"+UiApplication.isEventDispatchThread());
//      invalidateRange(0, bv.size()-1);
//      FileModel[] fileModelArr = new FileModel[fileModelVector.size()];
//      for(int i=0;i<fileModelVector.size();i++)
//          fileModelArr[i] = (FileModel)fileModelVector.elementAt(i);
//      set(fileModelArr);
    }

    public BigVector getFileModelVector(){
//      BigVector bv = new BigVector();
//      for(int i=0;i<this.getSize();i++)
//          bv.addElement(get(this, i));
        return bv;
    }

    public void set(Object[] or){

    }

    public Object get(ListField list, int index){
        return bv.elementAt(index);
    }

    public int getSize(){
        return bv.size();
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        return getSelectedIndex();
    }

    public int getPreferredWidth(ListField listField) {
        return Display.getWidth();
    }

    public void drawListRow(ListField listField, Graphics graphics
            , int index, int y, int width){
        System.out.println("DRWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
        FileModel fileModel = (FileModel)get(listField, index);
        if(fileModel.isFile())
            graphics.drawBitmap(0, y, width, fileBitmap.getHeight()
                    , fileBitmap, 0, 0);
        else
            graphics.drawBitmap(0, y, width, dirBitmap.getHeight()
                    , dirBitmap, 0, 0);
        switch(fileModel.getStatus()){
            case FileModel.ADD_STATUS:
                graphics.drawBitmap(0, y, width, addBitmap.getHeight()
                        , addBitmap, 0, 0);
                break;
            case FileModel.DEL_STATUS:
                graphics.drawBitmap(0, y, width,delBitmap.getHeight()
                        , delBitmap, 0, 0);
                break;
            case FileModel.MOD_STATUS:
                graphics.drawBitmap(0, y, width, modBitmap.getHeight()
                        , modBitmap, 0, 0);
                break;
            case FileModel.DOW_STATUS:
                break;
            case FileModel.NOR_STATUS:
                graphics.drawBitmap(0, y, width, norBitmap.getHeight()
                        , norBitmap, 0, 0);
                break;
            default:
                graphics.drawBitmap(0, y, width, novBitmap.getHeight()
                        , novBitmap, 0, 0);
                break;
        }
        graphics.drawText(fileModel.getName(), fileBitmap.getWidth(), y);
    }

}
解决方案

I don't think calling invalidate() on your ListField is enough. The invalidate() call really is a View layer method, that indicates that the field must be repainted. What you are really doing is indicating that the Model has changed.

See this other question on Stack Overflow

Try changing your code to something like this, using setSize():

public void setFileModelVector(BigVector fileModelVector){
    bv.removeAll();
    bv.addElements(fileModelVector.getContiguousArray());
    //invalidate();
    setSize(bv.size());
}

I also don't know how exactly you're handling ownership of the vector itself, but you could also probably just do this:

public void setFileModelVector(BigVector fileModelVector){
    bv = fileModelVector;
    //invalidate();
    setSize(bv.size());
}

since you were clearing out the entire vector, then converting the new vector to an array and then adding the array to the original vector. But, that's a separate issue, and isn't the reason you are seeing an empty ListField.

这篇关于ListField的方法无效不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:54