Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 1.57 KB

README.md

File metadata and controls

60 lines (48 loc) · 1.57 KB

ViewBuilder

ViewBuilder for Android is a library for easily building useful views like Tags, Spinner, AutoCompleteTextView, ...

Screenshots

Image

Setup

Add it to your build.gradle with:

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

and:

dependencies {
    compile 'com.github.DONIKAN:ViewBuilder:1.06'
}

How to use

  1. Initialize entries
List<Category> categories = DataFixture.getCategoies();
List<Entry> entries = new ArrayList<>();

for (Category category : categories) {
    entries.add(new Entry<Category>(category.getId(), category.getTitle(), category));
}

// select default first item
entries.get(0).setSelected(true);
  1. Build view
new TagBuilder(MainActivity.this)
        .setRecyclerView((RecyclerView) findViewById(R.id.rvTag))
        .setLayoutManager(ViewBuidler.LayoutManager.STAGGERED)
        .setOrientation(LinearLayout.HORIZONTAL)
        .setSpanCount(3)
        .setCustomSelectedStyle(R.style.CustomTagSelectedStyle, R.drawable.custom_bg_tag_selected)
        .setCustomUnselectedStyle(R.style.CustomTagUnselectedStyle, R.drawable.custom_bg_tag_unselected)
        .setEntries(entries)
        .setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void OnItemClick(Entry entry, int position) {
                Toast.makeText(MainActivity.this, "Tag : " + entry.toString(), Toast.LENGTH_LONG).show();
            }
        })
        .create();