【问题标题】:set array adapter list view设置数组适配器列表视图
【发布时间】:2015-11-24 15:54:35
【问题描述】:

此代码在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());
        }


        }

【问题讨论】:

  • 你从哪里调用 displayResultList?如果这是一个异步任务,来自 doInBackground 还是来自 onPostExecute?
  • @Mdlc,button.setOnClickListener

标签: android arraylist android-listview dataadapter


【解决方案1】:

从适配器更改数据后,您应该调用 notifyDataChange。 接下来,调试您的代码以找出哪个列上升错误。 除此之外,如果有出现错误的风险,请尝试“TRY CATCH”中的这段代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多