NeverEmptyListView


Source link: https://github.com/mskurt/NeverEmptyListView

NeverEmptyListView

This custom listview basically shows a holder view when it's adapter is empty. For example, you may fetch list datas from network and refresh your adapter with coming data. If the data is empty, your listview shows a huge blank space. With this custom listview, you can show a holder view instead of blank space and your design looks prettier.(Your minimum sdk should be 15 and higher)

Usage

1)First of all, add below in your build.gradle at the end of repositories:

repositories {

  // ...
  maven {
 url "https://jitpack.io" 
}
 
}
 

Add below dependency also.

compile 'com.github.mskurt:NeverEmptyListView:v1.0.1'  

2)Add the view to your layout xml. You must use features which are belong to NeverEmptyListView with custom namespace. It is recommended to use square size image for holderImageBackground.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<net.mskurt.neveremptylistviewlibrary.NeverEmptyListView

xmlns:custom="http://schemas.android.com/apk/res-auto"

android:id="@+id/listview"

android:layout_width="match_parent"

android:layout_height="match_parent"

custom:holderTextTopMargin="20dp"

custom:holderBackgroundColor="#ffffff"

custom:holderTextFontSize="9sp"

custom:holderTextColor="#000000"

custom:holderText="This is holder text."

custom:holderImageBackground="@drawable/an_example_image"/>  </RelativeLayout> 

3)Now you can set an adapter which has no item to your NeverEmptyListView.

//Create an empty adapter String[] values={

}
; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, values);
  //Set NeverEmptyListView's adapter NeverEmptyListView neverEmptyListView=(NeverEmptyListView)findViewById(R.id.listview);
 neverEmptyListView.setAdapter(adapter);

4)You can set a click listener for holder to do anything.

neverEmptyListView.setHolderClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {

//Do anything here
  
}
 
}
);

5)If you want to use notifyDataSetChange method of adapter, you should do it like below.

neverEmptyListView.notifyDataSetChanged(YOUR_ADAPTER);

6)If you need the listview at runtime (NeverEmptyListView is a custom view which contains a listview), you can get it like below.

neverEmptyListView.getListview();

For example, you can get the listview and setOnItemClickListener to it.

neverEmptyListView.getListview().setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

 
}
 
}
);

Holder View Customizing

Holder view is mostly customizable. You can use below feature list.

holderImageBackground : color or drawable reference holderImageSize : dimension in dp or px holderTextRightLeftMargin : dimension in dp or px holderTextTopMargin : dimension in dp or px holderTextFontSize : dimension in sp holderText : harcoded string or string reference holderTextColor : hardcoded color or color reference holderBackgroundColor : hardcoded color or color reference 

You can change these features at runtime

setHolderImageBackground(int drawableId) setHolderImageSize(int sizePixel) getHolderImageSize() setHolderText(String text) getHolderText() setHolderTextColor(int color) setHolderTextFontSize(int unit,float size) setHolderTextTypeFace(Typeface typeFace) setHolderTextLeftRightMargin(int marginPixel) setHolderTextTopMargin(int marginPixel) setHolderBackgroundColor(int color) 

Warning

If you want to use listview's basic attributes in xml, you should use it with custom namespace like below.

custom:listviewDivider custom:listviewDividerHeight custom:listviewFooterDividersEnabled custom:listviewHeaderDividersEnabled custom:listviewCacheColorHint custom:listviewDrawSelectorOnTop custom:listviewScrollingCache custom:listviewFastScrollEnabled custom:listviewChoiceMode custom:listviewListSelector custom:listviewTextFilterEnabled custom:listviewSmoothScrollbar custom:listviewStackFromBottom custom:listviewTranscriptMode 

Developed By

Sedat Kurt - www.mskurt.net - [email protected]

Licence

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. 

Resources

Are you tired of creating a new DialogFragment for each Dialog that you want to display?

This is an Android library that provides a simple implementation of a DialogFragment. It allows to define the content of the Dialog (and its button listeners) without having to create a new DialogFragment subclass.

Android App starter based on Android + MVP + Dagger2 + RxJava2 + Robolectric + Espresso + Mockito + JaCoCo.

Floating-ArcMenu A prety menu for all application

Android floating arc menu which reacts on scrolling events. Becomes visible when an attached target is scrolled up and invisible when scrolled down.

Ever get stuck with iOS image resources? Rather than write your own script, use this one to rename and move iOS image resources so they work for Android. Now converting iOS resources to Android ones is easy!

TwoStageRate is a library to help you promote your android app by prompting users to rate the app after using it for a few days. Also its two stage process ensures higher reviews to go to play store while getting useful feedback on lower ratings.

This is the official conference app for DroidKaigi 2017 Tokyo.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes