黑莓ListField:在更新过程中保持连续对焦 [英] Blackberry ListField: Maintaining row focus during an update

查看:326
本文介绍了黑莓ListField:在更新过程中保持连续对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的code刷新包含ListField数据后返回的XML Web服务。但是,刷新后或刷新它设置焦点在ListField的第一行。我不希望出现这种情况。我希望它保持刷新后当前的工作重点,用户甚至不会知道有一个刷新。

 保护无效onUiEngineAttached(附布尔){    如果(附后){        // TODO:你可能想显示某种动画        //进度界面这里,所以用户知道您正在获取数据        定时器定时器=新的Timer();        //安排Web服务任务运行每分钟        timer.schedule(新WebServiceTask(),0,60 * 1000);    }}公共自选画面(){    的setTitle(yQAforum);    listUsers.setEmptyString(未找到用户,0);    listUsers.setCallback(本);    加(listUsers);}
私有类WebServiceTask扩展的TimerTask {    公共无效的run(){        //获取来自Web服务的XML        串wsReturnString = GlobalV.Fetch_Webservice(myDs);        //解析返回的XML        SAXParserImpl的SAXParser =新SAXParserImpl();        ByteArrayInputStream的流=新ByteArrayInputStream进行(wsReturnString.getBytes());        尝试{
           saxparser.parse(流处理器);        }        赶上(例外五){           response.setText(无法​​解析响应。);        }        //现在,更新UI后面的UI线程上:        UiApplication.getUiApplication()的invokeLater(Runnable的新(){           公共无效的run(){              //从处理程序类返回矢量诗              listUsers.setSize(handler.getItem()大小());              //注意:如果你没有看到列表内容更新,您可能需要调用              // listUsers.invalidate();              //此处强制刷新。我不记得,如果调用的setSize()是不够的。           }        });    }}


解决方案

在昨天的评论,你需要您刷新列表之前录制目前主要集中行,然后重新设置焦点行,更新后即可。

因此​​,例如,在 WebServiceTask

  UiApplication.getUiApplication()的invokeLater(Runnable的新(){
       公共无效的run(){
          INT CURRENTINDEX = listUsers.getSelectedIndex();
          INT的scrollPosition = getMainManager()getVerticalScroll()。          //从处理程序类返回矢量诗
          listUsers.setSize(handler.getItem()大小());          listUsers.setSelectedIndex(CURRENTINDEX);
          。getMainManager()setVerticalScroll(的scrollPosition);
       }
    });

在code您在您的评论贴,你叫的setSelectedIndex()的结果getSelectedIndex() 你做了刷新,你想要什么,这将永远不会做。

After using the code below to refresh a ListField containing data returned in an xml web service. But after refresh or on refresh it sets focus to the first row in the ListField. I don't want that. I want it to maintain its current focus after refresh so that a user wont even know that there was a refresh.

protected void onUiEngineAttached(boolean attached) {

    if (attached) {

        // TODO: you might want to show some sort of animated

        //  progress UI here, so the user knows you are fetching data

        Timer timer = new Timer();

        // schedule the web service task to run every minute

        timer.schedule(new WebServiceTask(), 0, 60*1000);

    }

}

public MyScreen() {

    setTitle("yQAforum");

    listUsers.setEmptyString("No Users found", 0);

    listUsers.setCallback(this);

    add(listUsers);

}


private class WebServiceTask extends TimerTask {

    public void run() {

        //Fetch the xml from the web service

        String wsReturnString = GlobalV.Fetch_Webservice("myDs");

        //Parse returned xml

        SAXParserImpl saxparser = new SAXParserImpl();

        ByteArrayInputStream stream = new ByteArrayInputStream(wsReturnString.getBytes());

        try {


           saxparser.parse( stream, handler );

        } 

        catch ( Exception e ) {

           response.setText( "Unable to parse response.");

        }

        // now, update the UI back on the UI thread:

        UiApplication.getUiApplication().invokeLater(new Runnable() {

           public void run() {

              //Return vector sze from the handler class

              listUsers.setSize(handler.getItem().size());

              // Note: if you don't see the list content update, you might need to call

              //   listUsers.invalidate();

              // here to force a refresh.  I can't remember if calling setSize() is enough.

           }

        });

    }

}

解决方案

As I suggested in the comments after my answer yesterday, you need to record the currently focused row before you refresh your list, and then set the focused row again, immediately after the update.

So, for example, in the WebServiceTask:

    UiApplication.getUiApplication().invokeLater(new Runnable() {
       public void run() {
          int currentIndex = listUsers.getSelectedIndex();
          int scrollPosition = getMainManager().getVerticalScroll();

          //Return vector sze from the handler class
          listUsers.setSize(handler.getItem().size());

          listUsers.setSelectedIndex(currentIndex);
          getMainManager().setVerticalScroll(scrollPosition);
       }
    });

In the code you posted in your comment, you were calling setSelectedIndex() with the result of getSelectedIndex() after you did the refresh, which will never do what you want.

这篇关于黑莓ListField:在更新过程中保持连续对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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