设置数组适配器列表视图

时间:2015-08-30 13:54:33

标签: android arraylist android-listview dataadapter

此代码适用于BlueStacks,但当智能手机在日志中运行以下错误时显示。

错误:

The content of the adapter has changed but ListView did not receive a 
notification. Make sure the content of your adapter is not modified from a
background thread, but only from the UI thread. Make sure your adapter calls
notifyDataSetChanged() when its content changes. [in ListView(2131296334, class
android.widget.ListView) with Adapter(class android.widget.HeaderViewListAdapter)]

代码:

private void displayResultList() {

        try {
        array.clear();
        array=baseHelper.results;
        tView.setText("Size : " +array.size()+" "+ baseHelper.countmcur );

            try {

                if(arrayAdapter!=null)
                    arrayAdapter.notifyDataSetChanged();
                 arrayAdapter=new display();
                listV.setAdapter(arrayAdapter);
                arrayAdapter.notifyDataSetChanged();
            } catch (Exception e) {
             message.messages(contex, e.getMessage());
            }

            listV.setTextFilterEnabled(true);

        } catch (Exception e) {
             message.messages(contex, e.getMessage());
        }


        }

1 个答案:

答案 0 :(得分:0)

从适配器更改数据后,应调用notifyDataChange。 接下来,调试代码以找出哪个列上升错误。 除此之外,如果存在引发错误的风险,请在“TRY CATCH”亲爱的朋友中尝试此代码