Handles multiple display states for data-centric views
- Content state; shows the inner content of the View (as defined in XML)
- Loading state; shows a Loading state (as specified either via the
loadingLayoutattribute, or the default layout (res/layout/msv__loading.xml)
- For whatever
Viewyou want to switch out withMultiStateView, wrap theViewin aMultiStateViewnode. - In code, get your reference to the child of
MultiStateViewviaMultiStateView#getContentView()and cast that value as needed. There's no good reason to put anandroid:idon the childView.
Example:
-
Assuming you're starting with:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="match_parent" /> </LinearLayout> -
You should end up with something like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.meetme.android.multistateview.MultiStateView android:id="@+id/list_container" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:layout_width="fill_parent" android:layout_height="match_parent" /> </com.meetme.android.multistateview.MultiStateView> </LinearLayout>Example Notes 0.
android:id="@+id/list"was moved from theListViewto theMultiStateView0. It was also renamed tolist_containerto note that it now is the parent of theListView0. Any references in code should now useMultiStateView#getContentView()casted toListViewto reference theListViewchild. There's no good reason to put anidon theListView. See below. -
In code,
ListView list = (ListView) findViewById(R.id.list); -
Becomes
MultiStateView container = (MultiStateView) findViewById(R.id.list_container); ListView list = (ListView) container.getContentView(); -
To control the state of the
MultiStateView, use theMultiStateView#setState(State)method.container.setState(State.LOADING); -
By default, "Loading" indication uses the loading layout provided in the library (
res/layout/msv__loading.xml). To customize, you can add the custom attributemsvLoadingLayoutto theMultiStateViewin XML with a reference to the layout to inflate.
Apache 2.0
Copyright 2013 MeetMe, Inc.
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.
To make contributions, fork this repository, commit your changes, and submit a pull request.