0
後我有一個列表中,每行包括一個主項和子項的。我正在使用過濾器在用戶鍵入搜索編輯文本時刷新列表。 在列表中輸入項目時,根據輸入的字母顯示不一致,但是每個項目顯示兩次。 下面是我的代碼:ListView中顯示每個項目兩次濾波
public class NewReqFragment extends ListFragment
{
ListView newReqList;
LayoutInflater inflater;
String[] from = new String[] {"mainrow", "subrow"};
EditText searchBar = null;
SimpleAdapter sAdapter =null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
newReqList = this.getListView();
searchBar = (EditText)this.getActivity().findViewById(R.id.searchbar);
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for(int i = 0; i < ListItemStrings.NEWREQTITLES.length; i++)
{
HashMap<String, String> map = new HashMap<String, String>();
map.put("mainrow",ListItemStrings.NEWREQTITLES[i]);
map.put("subrow",ListItemStrings.NEWREQCHILDLIST[i]);
fillMaps.add(map);
}
sAdapter = new SimpleAdapter (this.getActivity(), fillMaps
, R.layout.simple_list_item_checkable_1,
from, new int[] {R.id.text1, R.id.text2});
newReqList.setAdapter(sAdapter);
searchBar.addTextChangedListener(filterTextWatcher);
}
private TextWatcher filterTextWatcher = new TextWatcher()
{
public void afterTextChanged(Editable s)
{
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
}
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
sAdapter.getFilter().filter(s);
sAdapter.notifyDataSetChanged();
}
};
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.newreqscrlayout, container,false);
return v;
}
}
任何人都可以請幫我找出什麼是錯的?