Android RecyclerView,使用 AdapterObserver 显示空结果视图
Android RecyclerView, uses of AdapterObserver for showing empty result view
我正在尝试开发一个 RecyclerView
能够在没有连接或没有数据时显示空视图的功能。我如何使用 AdapterObserver?从我的基本观点来看,它很复杂。我有一个 RecyclerView
和所需的东西(适配器、itemdecorator)。
首先,尝试重新格式化您的标题,使其更加清晰。其次,使用这个 class:
public static boolean testConection(Context context){
boolean HaveConnectedWifi = false;
boolean HaveConnectedMobile = false;
boolean result;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo)
{
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
HaveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
HaveConnectedMobile = true;
}
result = HaveConnectedWifi || HaveConnectedMobile;
return result;
}
那么,这样使用:
boolean connready = testConection(this);
if (connready) {
// show the RecyclerView
} else {
// hide the RecyclerView or show other view for no connection
Toast.makeText(getActivity(), "Check your connection", Toast.LENGTH_SHORT).show();
}
我正在尝试开发一个 RecyclerView
能够在没有连接或没有数据时显示空视图的功能。我如何使用 AdapterObserver?从我的基本观点来看,它很复杂。我有一个 RecyclerView
和所需的东西(适配器、itemdecorator)。
首先,尝试重新格式化您的标题,使其更加清晰。其次,使用这个 class:
public static boolean testConection(Context context){
boolean HaveConnectedWifi = false;
boolean HaveConnectedMobile = false;
boolean result;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo)
{
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
HaveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
HaveConnectedMobile = true;
}
result = HaveConnectedWifi || HaveConnectedMobile;
return result;
}
那么,这样使用:
boolean connready = testConection(this);
if (connready) {
// show the RecyclerView
} else {
// hide the RecyclerView or show other view for no connection
Toast.makeText(getActivity(), "Check your connection", Toast.LENGTH_SHORT).show();
}