选择后列表似乎再次短暂显示

发布于 2024-11-07 10:13:55 字数 1871 浏览 0 评论 0原文

有人可以帮我吗!我是 Android 新手,正在开始我的第一个应用程序。

这个想法是从“主/第一个”活动启动第二个(列表活动)并将选定的对象返回到第一个。我使用处理程序来检索类名称列表(现在从 array.xml 中),实例化类并将它们添加到数组中。我正在扩展数组适配器来显示它。

第一个活动中的 onActivityResult() 使用 returnData.getParcelableExtra() 来“重新膨胀”所选项目对象。

一切正常,但从列表中选择一个项目后,列表似乎会在返回第一个活动之前再次显示一瞬间。这可能是正常行为,只是“感觉”和看起来不对。 我做错了什么吗? 的代码

   @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Intent returnIntent = new Intent();
    returnIntent.putExtra("my.source.selected", (Thing)   this.getListAdapter().getItem(position));
    setResult(RESULT_OK, returnIntent);
    ExampleApplication application = (ExampleApplication) getApplication();
    application.setCurrentlySelectedFormat(this.things.get(position));
    finish(); //gives back the handle to parent activity
}

这是 onListItemClick()和处理程序

    private final Handler handler = new Handler() {
    public void handleMessage(final Message msg) {
        super.handleMessage(msg);
        progressDialog.dismiss();
        if ((things == null || things.size() == 0)) {
            empty.setText("No things found");
        } else {
            setListAdapter(new ThingAdapter(SelectThing.this, R.layout.row, things));
        }
    }
};

    private void loadThings() {     
    if (things == null) {           
        final ThingFetcher ff = new ThingFetcher();         
        this.progressDialog = ProgressDialog.show(this, "Working...", " Retrieving things");        
        new Thread() {
            public void run() {
                things = ff.fetchFormats(SelectThing.this);
                handler.sendEmptyMessage(0);
            }
        }.start();
    }
}

@Override
protected void onResume() {
    super.onResume();
    loadThings();
}

...我的适配器已经过优化,似乎建议使用视图持有者并重新使用 ConvertView 等。

任何帮助将不胜感激。

Can somebody help me please! I'm new to android and am starting my first app.

The idea is to start a second (list activity) from a "main/first" activity and return a selected object back to the first. I'm doing this using a handler to retrieve the list of class names (from array.xml for now), instantiating the classes and adding them to the array. I'm extending array adapter to display it.

onActivityResult() in the first activity uses returnData.getParcelableExtra() to "re-inflate" the selected item object.

Everything works ok but after selecting an item from the list, the list seems to get shown again for a split second before returning to the first activity. This might be normal behaviour put it just "feels" and looks wrong.
Am I doing something wrong? Here's the code for the onListItemClick()

   @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Intent returnIntent = new Intent();
    returnIntent.putExtra("my.source.selected", (Thing)   this.getListAdapter().getItem(position));
    setResult(RESULT_OK, returnIntent);
    ExampleApplication application = (ExampleApplication) getApplication();
    application.setCurrentlySelectedFormat(this.things.get(position));
    finish(); //gives back the handle to parent activity
}

and for the handler...

    private final Handler handler = new Handler() {
    public void handleMessage(final Message msg) {
        super.handleMessage(msg);
        progressDialog.dismiss();
        if ((things == null || things.size() == 0)) {
            empty.setText("No things found");
        } else {
            setListAdapter(new ThingAdapter(SelectThing.this, R.layout.row, things));
        }
    }
};

    private void loadThings() {     
    if (things == null) {           
        final ThingFetcher ff = new ThingFetcher();         
        this.progressDialog = ProgressDialog.show(this, "Working...", " Retrieving things");        
        new Thread() {
            public void run() {
                things = ff.fetchFormats(SelectThing.this);
                handler.sendEmptyMessage(0);
            }
        }.start();
    }
}

@Override
protected void onResume() {
    super.onResume();
    loadThings();
}

My adapter is optimised as seems to be recommended with view holder and re-using convertView etc.

Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巨坚强 2024-11-14 10:13:55

似乎问题不在代码中,而在列表行中视图的布局 xml 中。
我遵循了这个建议 http://android-developers.blogspot .com/2009/02/android-layout-tricks-1.html 似乎已经解决了问题。没有简短的“重新渲染”列表。

Seems the problem is not in the code but in the layout xml for the views in the rows in the list.
I followed this suggestion http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html and it seems to have fixed the problem. No brief "re-rendering" of the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文