0

我的 Android 应用程序中有一个搜索选项,它使用 Web 服务(在搜索栏中搜索关键字时)并在我的屏幕上显示结果。下一次,当我搜索不同的关键字时,结果将附加到第一个结果并显示。我想要的是,擦除/清除第一个结果,然后显示第二个结果,而不是附加到第一个结果。请作为 Android 新手帮助。

public class Srch_Widget extends ListActivity {

ListView lv;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mysearchscreen);

//In the search box, i will be typing an alphabet and click on "GO button"

goButton.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

//I'm using webservices to retrieve data(JSON String) and will get "EmpName", "EmpID",
"Salary" and the data will be in a single list called "searchlist" that I used below in
ser_listadapter.(if you want I can paste the entire webservices)

ser_listadapter();

}

});
}

public void ser_listadapter() {
ListAdapter adapter = new SimpleAdapter(this,searchlist,
            R.layout.searchmain, new String[] { "EmpName", "EmpID",
                    "Salary" }, new int[] {
                    R.id.eid, R.id.ename, R.id.sal});

//"searchmain" layout contains 3 textviews with id's: eid,ename,sal

setListAdapter(adapter);
lv = getListView();
lv.setTextFilterEnabled(true);
}
}
4

1 回答 1

0

确保在您的 onClick 中和调用您的网络服务之前清除您的 searchList:

public void onClick(View v) {
    searchlist.clear();
    callwebservice(searchlist);
    ser_listadapter();
}
于 2014-02-17T22:04:45.067 回答