我在片段中有一个空白的回收者视图。收到GCM通知后,我想拨打网络服务。该Web服务将数据存储到空白数据库中。完成所有操作后,如何通知Recycler视图以使用新数据库内容更新自身?
我只是停留在需要以某种方式通知回收者视图以更新自身的部分。我实现了这个https://gist.github.com/skyfishjy/443b7448f59be978bc59,但它仅在数据库中已有数据时才有效。它在我的场景中不起作用。
我正在提供我目前的代码,以便更好地理解问题:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(viewlayout1){
view = mInflater.inflate(R.layout.layout1,null);
}else{
view = mInflater.inflate(R.layout.layout2,null);
}
setContentView(view);
/*******************/
}
我的ContentProvider
app_1 | File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
app_1 | response = wrapped_callback(request, callback_args, *callback_kwargs)
app_1 | File "/code/invitations/views.py", line 102, in request_invite
app_1 | msg.send()
app_1 | File "/usr/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
app_1 | return self.get_connection(fail_silently).send_messages([self])
app_1 | File "/usr/local/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 81, in send_messages
app_1 | sent = self._send(message)
app_1 | File "/usr/local/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 132, in _send
app_1 | response = requests.post(api_url, data=api_data)
app_1 | File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 109, in post
app_1 | return request('post', url, data=data, json=json, *kwargs)
app_1 | File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
app_1 | response = session.request(method=method, url=url, *kwargs)
app_1 | File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
app_1 | resp = self.send(prep, *send_kwargs)
app_1 | File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
app_1 | r = adapter.send(request, *kwargs)
app_1 | File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
app_1 | raise SSLError(e, request=request)
app_1 | SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
答案 0 :(得分:0)
我只是被困在需要通知回收者视图的部分 以某种方式更新自己。我实现了这个 https://gist.github.com/skyfishjy/443b7448f59be978bc59,但它有效 只有当数据库中已存在数据时它不适用于我的 场景。
如果您有ContentProvider
并且使用CursorLoader,则在通知正确的Uri
后,框架应该再次查询数据库。如果您没有使用ContentProvider,则可以使用LocalBroadcastManger在数据库中插入新数据后广播事件。 Fragment应该注册到此事件并手动重新查询数据库
答案 1 :(得分:-1)
您可以使用EventBus向适配器发送消息以致电notifyDataSetChange