Code Monkey home page Code Monkey logo

netstatelayout's Introduction

netstatelayout extend framelayout.you can custom view to show net state: loading,error,ok.

How to use

the library as dependency

Add the library as dependency to your build.gradle file.

dependencies {
	//other dependencies...
	compile 'com.xingliuhua:libnetstatelayout:1.0.1'
}

implement interface

implement INetErrorView and INetLoadingView to custom your UI .of course,you can use SimpleNetErrorView and SimpleNetLoadingView.

public class MyNetErrorView implements INetErrorView {
   ...
}
public class MyNetLoadingView implements INetLoadingView {
    ...
}

set view

you can set view by code or xml

  1. set view by code
 mNetStateLayout.setNetErrorView(new MyNetErrorView());
 mNetStateLayout.setNetLoadingView(new MyNetLoadingView());

2.set view by xml

<com.xingliuhua.libnetstatelayout.view.NetStateLayout
        android:id="@+id/net_state_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:net_error="com.xingliuhua.libnetstatelayout.view.MyNetErrorView"
        app:net_loading="com.xingliuhua.libnetstatelayout.view.MyNetLoadingView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="by xml attr"/>

            <Button
                android:id="@+id/test"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="to second activity"/>
        </LinearLayout>
</com.xingliuhua.libnetstatelayout.view.NetStateLayout>

switch state

public class MainActivity extends AppCompatActivity {
    private NetStateLayout mNetStateLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, SecondActivity.class));
            }
        });

        mNetStateLayout = (NetStateLayout) findViewById(R.id.net_state_layout);
        mNetStateLayout.setContentState(NetStateLayout.CONTENT_STATE_SHOW_LOADING);
        mNetStateLayout.setOnRetryClickListener(new INetErrorView.OnRetryClickListener() {
            @Override
            public void onRetryClicked() {
                mNetStateLayout.setContentState(NetStateLayout.CONTENT_STATE_HIDE);
            }
        });
        mHandler.sendEmptyMessageDelayed(0, 3000);

    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mNetStateLayout.setContentState(NetStateLayout.CONTENT_STATE_SHOW_NET_ERROR);
        }
    };
}

netstatelayout's People

Contributors

xingliuhua avatar

Watchers

James Cloos avatar

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.