2

我正在尝试ListView按字母顺序排序。

我有一个名为的数据模型类AiringModel(),它有一个名为getName(). 我需要根据来自的返回值订购 ListView getName()

到目前为止,我尝试Comparator在适配器上使用 a ,sort()如下所示:

final ArrayAdapter<AiringModel> adapter = new TrackingAdapter(
                activity.getSherlockActivity(), resultList);
        //resultList -> List<AiringModel> list
        adapter.sort(new Comparator<AiringModel>() {
            @Override
            public int compare(AiringModel lhs, AiringModel rhs) {
                // TODO Auto-generated method stub
                return lhs.getName().compareTo(rhs.getName());
            }
        });
        trackingAdapter = adapter;
        activity.setListAdapter(adapter);

但这不起作用,没有错误,ListView只是保持完全相同。

知道我做错了什么吗?

编辑:

该列表根据日志完美排序,所以我又去挖掘了一些,结果发现我正在另一个线程中重置适配器,叹息。感谢您给我一些想法,但它有所帮助。

4

1 回答 1

3

试着打电话

adapter.notifyDataSetChanged();

将其设置为ListView.

于 2013-03-14T22:51:01.543 回答