At first, clone the project and run the demo; Secondly, copy the code to your project and modify it to adapt your business.
Here are the common way to setup setting view:
SettingRecyclerAdapter settingRecyclerAdapter= new SettingRecyclerAdapter();
like this: settings.xml
<settings xmlns:android="http://schemas.android.com/apk/res/android">
<header
name="Normal Setting"/>
<item
android:id="@+id/id"
name="ID"
secondaryTxt="23333"/>
<item
android:id="@+id/name"
name="Name"
secondaryTxt="Lshare"/>
...
</settings>
use XmlResourceParser to parse the xml file you defined before(like this: SettingActivity#loadData), and then call settingRecyclerAdapter.addAll(settingItemList);
to add them to adapter.
Just call settingRecyclerAdapter.setOnItemClickListener(this);
and then handle the event like follow:
@Override public void onItemClick(int id, SettingItem item) {
Util.toast(this, item);
if (id == R.id.name) {
settingRecyclerAdapter.updateSecondaryText(id, "Here it go");
}
}
recyclerView.setLayoutManager(
new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(settingRecyclerAdapter);
recyclerView.addItemDecoration(new PinnedHeaderItemDecoration());
- AdapterDelegates: https://github.com/sockeqwe/AdapterDelegates
- pinned-section-item-decoration: https://github.com/takahr/pinned-section-item-decoration
Copyright 2016 Lshare
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.