Then just like in the linked answerprivate class MyNamesAdapter extends RealmBaseAdapter<RealmPhoneCallLogs> implements Filterable { public MyNamesAdapter(OrderedRealmCollection<RealmPhoneCallLogs> data) { super(data); } public class ViewHolder { TextView number; TextView callType; TextView startTime; TextView contactName; TextView callDuration; TextView fileSize; ImageView contactPhoto; ImageView callSymbol; } @Override public View getView(int position, View convertView, ViewGroup parent) { final RealmPhoneCallLogs realmPhoneCallLogs = getItem(position); ViewHolder viewHolder; if(convertView == null) { viewHolder = new ViewHolder(); LayoutInflater inflater = LayoutInflater.from(getContext()); convertView = inflater.inflate(R.layout.calllog_layout, parent, false); viewHolder.number = (TextView) convertView.findViewById(R.id.missedNumber); viewHolder.startTime = (TextView) convertView.findViewById(R.id.missedStartTime); viewHolder.contactName = (TextView) convertView.findViewById(R.id.missedContactName); viewHolder.callDuration = (TextView) convertView.findViewById(R.id.missedCallDuration); viewHolder.fileSize = (TextView) convertView.findViewById(R.id.missedFileSize); viewHolder.contactPhoto = (ImageView) convertView.findViewById(R.id.missedImage); viewHolder.callSymbol = (ImageView) convertView.findViewById(R.id.callSymbol); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } if(adapterData != null) { viewHolder.number.setText(realmPhoneCallLogs.getNumber()); viewHolder.contactName.setText(getContactName(realmPhoneCallLogs.getNumber())); viewHolder.callDuration.setText(getTime(realmPhoneCallLogs.getCallDuration())); viewHolder.startTime.setText(realmPhoneCallLogs.getStartTime()); viewHolder.contactPhoto.setImageBitmap(getContactsImage(realmPhoneCallLogs.getNumber())); String path = new String(Environment.getExternalStorageDirectory() + "/NewCallLogs/" + realmPhoneCallLogs .getCallRecords()); File file = new File(path); String size; long filesize = file.length(); long fileSizeInKB = filesize / 1024; long fileSizeInMB = fileSizeInKB / 1024; if(fileSizeInKB >= 1024) { size = fileSizeInMB + " Mb"; } else { size = fileSizeInKB + " Kb"; } if(!size.isEmpty()) { viewHolder.fileSize.setText(size); } else { viewHolder.fileSize.setText(0); } if("I".equals(realmPhoneCallLogs.getCallType())) { viewHolder.callSymbol.setImageResource(R.mipmap.call_received); } else if("O".equals(realmPhoneCallLogs.getCallType())) { viewHolder.callSymbol.setImageResource(R.mipmap.call_made); } else if("UA".equals(realmPhoneCallLogs.getCallStatus())) { viewHolder.callSymbol.setImageResource(R.mipmap.call_missed); } return convertView; } return convertView; }// filtering public void filterResults(String text) { text = text == null ? null : text.toLowerCase().trim(); if(text == null || "".equals(text)) { updateData(realm.where(RealmPhoneCallLogs.class).findAllSorted("id"); } else { updateData(realm.where(RealmPhoneCallLogs.class) .contains("number", text, Case.INSENSITIVE) .findAllSorted("id")); } } public Filter getFilter() { return new MyNamesFilter(this); } private class MyNamesFilter extends Filter { private final MyNamesAdapter adapter; private MyNamesFilter(MyNamesAdapter adapter) { super(); this.adapter = adapter; } @Override protected FilterResults performFiltering(CharSequence constraint) { return new FilterResults(); } @Override protected void publishResults(CharSequence constraint, FilterResults results) { adapter.filterResults(constraint.toString()); } }}对于过滤领域,您还可以查看有关查询的官方文档 For filtering Realm, you can also check out the official documentation on queries. 这篇关于如何过滤领域适配器中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 12:31