但是ListView的内容没有更新;
在此输入内容,点击查询,
发现查询之前,listview会更新到上次查询到的数据;这个应该是你穿的值不对了;adapter更新的时候还是以前的值啊;在更新这部分的list穿值可能有点绕,你应该检查下你的list。

解决方案 »

  1.   

    我在每次查询时,都是把输入的值和adapter中list的值打印出来的,这些事符合要求的,但是ListView上总是不对
      

  2.   

    不知道呢,adapter更新了,但是ListView没有更新
      

  3.   

    你在adapter的 getview 里面输出你的list,不要再传之前输出,看看值对不
      

  4.   

    应该怎样来更新getView()里的list呢?
      

  5.   

    将list设为静态的,在使用adapter的notifyDataSetChanged()方法之前,
     list.clear;
    在重新将查询的值赋给list;试试
      

  6.   

    还是不可以,getView这个方法没有调用
      

  7.   

    把list和adapter都设成全局的,第二次拿到数据的时候,重新定义一个list_tmp,把拿到的数据存进来,再把这个list_tmp加到全局的list中,然后adapter.notifyDataSetChanged()试试!!
      

  8.   


    public class SearchActivity extends Activity {
    private AppSetting appSetting = null;
    private LinearLayout toolBar;
    private EditText editText;
    private Button btnSearch;
    private ListView lstEnterprise;
    private MyHandler myHandler = null;
    SearchAdapter sa = null;
    List<Enterprise> lst = null;
    SearchActivity oThis = this;
    private String key = "";

    public final int handler_ok = 10101;



     @Override
     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
         setContentView(R.layout.search);
         Intent intent = getIntent();
       key=intent.getStringExtra("key") ;
       
         editText = (EditText)findViewById(R.id.EditSearch);
         editText.setText(key);
         btnSearch = (Button)findViewById(R.id.BtnSearch);
         lstEnterprise = (ListView)findViewById(R.id.lstEnterprise);
     toolBar = (LinearLayout) findViewById(R.id.toolBar);
         setToolBar(new String[]{ "查看地图","重新搜索"},new int[]{0,1});
         lst = this.getEnterpriseByKey(key);
         sa = new SearchAdapter(oThis,lst);
         lstEnterprise.setAdapter(sa);
         HandlerThread handlerThread = new HandlerThread("search");
         handlerThread.start();
         myHandler = new MyHandler(handlerThread.getLooper());
         
         Helper.showProgress(oThis,"请稍候, 正在搜索中");
     myHandler.post(runnable);
     sa.updateLst(lst);
         
         btnSearch.setOnClickListener(new OnClickListener(){ @Override
    public void onClick(View v) {
    //重新搜索
    String preKey = key;
    key = editText.getText().toString().trim();
    if(key.equals("") || key==""){
    Toast.makeText(getApplicationContext(), "你输入的是空值", Toast.LENGTH_SHORT).show();
    }else{
    if(preKey.equals(key) || preKey==key){

    }else{
    Helper.showProgress(oThis,"请稍候, 正在搜索中");
    myHandler.post(runnable);
    lst = oThis.getEnterpriseByKey(editText.getText().toString());
    sa.updateLst(lst);
    }
    }


    }

         });
         
         lstEnterprise.setOnItemClickListener(new OnItemClickListener(){ @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
    long id) {

    String msg=lst.get(position).getEntId();
    Intent intent2 = new Intent();
    intent2.putExtra("Msg", msg);
    setResult(3, intent2);

    finish();
    }
          
         });
         
     }
    方法
    sa.updateLst(lst);
    更新adapter里的list,同时调用notifyDataSetChanged()
      

  9.   

    list.remove(list);
    list.AddAll(otherlist);
    ad.notifyDataSetChanged();
    这样就可以了我之前也遇到了这个问题,后来查了一下,看到这个帖子以为能找到答案了,结果还是没有,后来在另外一个地方找到了一个帖子,说得比较详细的。
    造成这个问题的原因,其实是list=otherList;的时候,这个list也就相当于再执行了一次new ArratList<>();所以就会导致Adapter与这个list只见的联系丢失了。解决办法就是保证原来的list的数据不变,然后再后面addall(otherList)进去,如果数据有了重叠,可以先list.remove(list);也就是先清除list里面的数据,然后在addall一次,最后执行.notifyDataSetChanged();