MultiStateView

Additional

Language
Kotlin
Version
2.0 (Jun 23, 2019)
Created
Apr 22, 2015
Updated
Jun 23, 2019
Owner
Kenny (Kennyc1012)
Contributors
Kenny (Kennyc1012)
jiangecho
曾祥彬 (zeng1990java)
LiqiangZhang (StormGens)
wingsum93
5
Activity
Badge
Generate
Download
Source code
APK file

Show card

MultiStateView

Android View that displays different content based on its state. Based off of MeetMe/MultiStateView

The four different states the view can be in are:

  • Content
  • Empty
  • Error
  • Loading

Using MultiStateView

MultiStateView can be used the same as any other view by adding it as a layout file via XML

<com.kennyc.view.MultiStateView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/multiStateView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:msv_errorView="@layout/error_view"
    app:msv_emptyView="@layout/empty_view"
    app:msv_loadingView="@layout/loading_view"
    app:msv_viewState="loading">
    
      <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@android:layout/simple_list_item_1" />

</com.kennyc.view.MultiStateView>

The attributes to set for MultiStateView are

<attr name="msv_loadingView" format="reference" />
<attr name="msv_emptyView" format="reference" />
<attr name="msv_errorView" format="reference" />
<attr name="msv_viewState" format="enum">
<attr name="msv_animateViewChanges" format="boolean" />

msv_loadingView is the view to be used for VIEW_STATE_LOADING msv_viewState is the ViewState for the MultiStateViewVIEW_STATE_CONTENT is determined by whatever is inside of the tags via XML. NOTE a Content view must be set for the view to function, this is by design.msv_animateViewChanges is a flag to set whether the views should animate in and out when switching states. false by default

msv_errorView is the view to be used for VIEW_STATE_ERROR
msv_emptyView is the view to be used for VIEW_STATE_EMPTY


To switch the state of MultiStateView, simply call

multiStateView.viewState = @ViewState state:Int

or in java

multiStateView.setViewState(@ViewState int state)

You can also get the View for the accompanying ViewState by calling

multiStateView.getView(@ViewState state:Int):View?

or in java

@Nullable
public View getView(@ViewState int state)

Including in your project

To include MultiStateView in your project, make the following changes to your build.gradle file

Add repository

repositories {
    maven { url 'https://jitpack.io' }
}

Add dependency

dependencies {
    implementation  'com.github.Kennyc1012:MultiStateView:2.0'
}

Contribution

Pull requests are welcomed and encouraged. If you experience any bugs, please file an issue

License

Copyright 2015 Kenny Campagna

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.