我正在尝试在ListView
. 我ListView
由HashMap
in组成ArrayList
,我设法实现了逻辑,但我猜每次文本更改时,我的方法中有很多对象和内存分配。因此,我正在寻找更少的内存分配逻辑来搜索我ListView
的HashMap
inArrayList
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//textlength = searchBar.getText().length();
//text_sort.clear();
sortedArrayList.clear();
for (int i = 0; i < myHistList.size(); i++) {
HashMap<String, String> hash = new HashMap<String, String>();
hash = myHistList.get(i);
if (hash.get("myName").toLowerCase().indexOf(searchBar.getText().toString().toLowerCase()) != -1) {
String callerNum1 = hash.get("myNumber");
String myName1 = hash.get("myName");
HashMap<String, String> searchedHash = new HashMap<String, String>();
// adding each child node to HashMap key => value
searchedHash.put("myNumber", callerNum1);
searchedHash.put("myName", myName1);
recordingFile1);
// adding HashList to ArrayList
sortedArrayList.add(searchedHash);
}
}
ListView actualLv = mPullRefreshListView.getRefreshableView();
actualLv.setAdapter(new myHistoryListAdapter(myHistory.this, sortedArrayList));
}