-
Notifications
You must be signed in to change notification settings - Fork 377
Components
ZieIony edited this page Jul 14, 2017
·
2 revisions
Components are simple building blocks based on Data Binding. Components provide the most accurate, complete layouts of rows, cells, dividers and headers described in Material Design guidelines. Each layout has a corresponding item interface and a default item implementation. In addition to components and items there are adapters, which provide convenient way of preparing complex, RecyclerView-based lists.
The following code can be used to create a registration form using components and a RecyclerView.
RecyclerView recycler = findViewById(R.id.recycler);
recycler.setLayoutManager(new LinearLayoutManager(this));
RowListAdapter<Serializable> adapter = new RowListAdapter<>(DefaultIconEditTextItem.class, IconEditTextRow::new);
adapter.addFactory(PaddingItem.class, PaddingRow::new);
adapter.addFactory(DividerItem.class, DividerRow::new);
adapter.addFactory(DefaultIconPasswordItem.class, IconPasswordRow::new);
adapter.addFactory(DefaultIconDropDownItem.class, IconDropDownRow::new);
recycler.setAdapter(adapter);
adapter.setItems(Arrays.asList(
new PaddingItem(getResources().getDimensionPixelSize(R.dimen.carbon_paddingHalf)),
new DefaultIconEditTextItem(new VectorDrawable(getResources(), R.raw.profile), "login", ""),
new DefaultIconEditTextItem(new VectorDrawable(getResources(), R.raw.email), "email", ""),
new DefaultIconPasswordItem(new VectorDrawable(getResources(), R.raw.lock), "password", ""),
new DefaultIconPasswordItem(null, "retype password", ""),
new DefaultIconDropDownItem<>(new VectorDrawable(getResources(), R.raw.gender), "sex", new String[]{"Male", "Female"}, "Male"),
new PaddingItem(getResources().getDimensionPixelSize(R.dimen.carbon_paddingHalf))));
Copyright 2015 Marcin Korniluk 'Zielony'