最好的方法来显示Android中的网络错误,具有“点击重试"选项 [英] Best approach to show network error in android in Android with Tap to Retry option

查看:530
本文介绍了最好的方法来显示Android中的网络错误,具有“点击重试"选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有Navigation Drawer,除了主要应用程序流程外,还有几个Fragments和几个新的Activity.

I have Navigation Drawer in my application with several Fragments and few new Activity also apart from main application flow.

  • 当前功能
    要导航到每个Fragment,需要网络,如果出现任何网络错误,我通常会显示Dialog.用户需要单击确定"按钮,然后再次返回导航抽屉重试.
  • 我正在尝试的新方法
    应该显示用户,并且错误屏幕类似于LinkedIn android app,并具有重试选项.
  • Current Functionality
    For navigating to each Fragment, Network is required and in case of any network error, I used to show Dialog. User needs to click on "OK" button and again go back to navigation drawer to retry.
  • New Approach I am trying
    User should be shown and error screen similar to LinkedIn android app with option to retry.

由于内部Fragments处理回叫可能很麻烦,如何有效处理这种情况?
对于个人活动,这很容易实现,但担心导航抽屉和内部碎片.
有什么建议吗?

As inner Fragments and handling call back can be cumbersome, how to handle this situation efficiently?
For individual Activities this can be achieved easily, but worried about the Navigation Drawer and inner Fragments.
Any suggestions?

推荐答案

将此错误布局隐藏在此片段中.如果出现任何网络错误,则将其可见性更改为VISIBLE.并在此隐藏布局中添加一个按钮,以调用相同的方法来检查网络连接等.

Make this error layout hidden in this fragment. When there is any network error then change its visibility to VISIBLE. and in this hidden layout add a button to recall same method to check network connection etc.

假设您有类似xml的片段- 片段-
相对布局包括- 1.-所有版式(VISIBLE)& 2.-通过按钮(GONE)隐藏网络错误布局

Let say you have fragment xml like - fragment -
Relative Layout consisting - 1. -All layouts (VISIBLE) & 2. -Hidden network error layout with a button (GONE)

当出现网络错误时,将1.的可见性更改为-GONE 和2.对可见性的可见性

When there is network error then change 1. 's visibility to - GONE and 2.'s visibility to VISIBLE

并重试按钮调用-

checkNetworkConnectionCall(); 

我希望这能解决您的问题.

I hope this will solve you problem.

这篇关于最好的方法来显示Android中的网络错误,具有“点击重试"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆