我的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);
}
}
答案 0 :(得分:0)
确保在调用Web服务之前清除onClick中的searchList:
public void onClick(View v) {
searchlist.clear();
callwebservice(searchlist);
ser_listadapter();
}