Giter Site home page Giter Site logo

android-multistateview's Introduction

MultiStateView

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 loadingLayout attribute, or the default layout (res/layout/msv__loading.xml)

The following shows examples (using default layouts) for Loading, General Error, Network Error, and the Content states (where we've made the "Hello World" the content) in respective order.

Loading state  General error state

Network error state  Content state

Usage

  • For whatever View you want to switch out with MultiStateView, wrap the View in a MultiStateView node.
  • In code, get your reference to the child of MultiStateView via MultiStateView#getContentView() and cast that value as needed. There's no good reason to put an android:id on the child View.

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 the ListView to the MultiStateView 0. It was also renamed to list_container to note that it now is the parent of the ListView 0. Any references in code should now use MultiStateView#getContentView() casted to ListView to reference the ListView child. There's no good reason to put an id on the ListView. 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 the MultiStateView#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 attribute msvLoadingLayout to the MultiStateView in XML with a reference to the layout to inflate.

Contributors

License

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.

Contributing

To make contributions, fork this repository, commit your changes, and submit a pull request.

android-multistateview's People

Contributors

dallasgutauckis avatar jimmithy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-multistateview's Issues

multiple custom states?

I'm not really seeing how I would have multiple custom states.

<com.meetme.android.multistateview.MultiStateView
android:layout_below="@id/state"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content">
<TextView
android:text="@string/hello_world"
android:gravity="center"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#f33"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.meetme.android.multistateview.MultiStateView>

what if i want a textview , a listview, a editext, a imageview all to be different states.

Address multiple elements inside container?

what if I have mutiple elements inside the multistateview?

how do you address them each?

TextView = (TextView) container.getContentView();

What if there is another textview inside the container
since ids arent being, i'm lost on how to address multiple elements?

Increase minSdkVersion to prevent merging implied external storage permissions

android:uses-permission#android.permission.WRITE_EXTERNAL_STORAGE
IMPLIED from /Users/winsonchiu/Projects/MyApplication/app/src/main/AndroidManifest.xml:2:1-20:12 reason: com.meetme.android.multistateview has a targetSdkVersion < 4
android:uses-permission#android.permission.READ_PHONE_STATE
IMPLIED from /Users/winsonchiu/Projects/MyApplication/app/src/main/AndroidManifest.xml:2:1-20:12 reason: com.meetme.android.multistateview has a targetSdkVersion < 4
android:uses-permission#android.permission.READ_EXTERNAL_STORAGE
IMPLIED from /Users/winsonchiu/Projects/MyApplication/app/src/main/AndroidManifest.xml:2:1-20:12 reason: com.meetme.android.multistateview requested WRITE_EXTERNAL_STORAGE

I'm fairly certain this is caused by the minSdkVersion. Although it might not be.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.