做这件事的简单方法是
PostItinerarySearchCityAdapter extends RealmBaseAdapter<PostUserItinerary>
,使用
RealmResults<PostUserItinerary>
直接,然后删除您直接拨打的任何电话
adapter.notifyDataSetChanged();
.
Activity
和
Adapter
在王国的样本中。
class MyListAdapter extends RealmBaseAdapter<PostUserItinerary> implements ListAdapter {
private static class ViewHolder {
TextView countText;
CheckBox deleteCheckBox;
}
MyListAdapter(OrderedRealmCollection<Counter> realmResults) {
super(realmResults);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row, parent, false);
viewHolder = new ViewHolder();
viewHolder.countText = (TextView) convertView.findViewById(R.id.textview);
viewHolder.deleteCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final PostUserItinerary item = getItem(position);
...
return convertView;
}
}
和
public class ListViewExampleActivity extends AppCompatActivity {
private Realm realm;
private MyListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
realm = Realm.getDefaultInstance();
// RealmResults are "live" views, that are automatically kept up to date, even when changes happen
// on a background thread. The RealmBaseAdapter will automatically keep track of changes and will
// automatically refresh when a change is detected.
adapter = new MyListAdapter(realm.where(PostUserItinerary.class).findAllAsync());