Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbcr committed Apr 8, 2016
1 parent b5b7152 commit af2b604
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 9 deletions.
45 changes: 37 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
**/build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio
.navigation/
.idea/
**/*.iml

# Android Studio captures folder
captures/

# .DS_Store files
**/.DS_Store
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Add OkAdapter dependency to project level build.gradle.

```gradle
dependencies {
compile 'com.github.FuckBoilerplate:OkAdapters:0.0.1'
compile 'com.github.FuckBoilerplate:OkAdapters:0.0.2'
}
```

Expand Down Expand Up @@ -63,4 +63,51 @@ Create a class which extends from any Android `ViewGroup` and implements [BindVi
recyclerView.setAdapter(adapter);

```

## Spinner
Create a class which extends from any Android `ViewGroup` and implements [OkSpinnerAdapter.Binder](https://github.com/FuckBoilerplate/OkAdapters/blob/master/library/src/main/java/library/spinner/OkSpinnerAdapter.java). This approach allows to encapsulate the binding between the data and the `view`.

```java

public class YourModelViewGroup extends FrameLayout implements OkSpinnerAdapter.Binder<YourModel> {

public YourModelViewGroup(Context context) {
super(context);

View view = LayoutInflater.from(getContext()).inflate(R.layout.your_model_view_group, this, true);
ButterKnife.bind(this, view);
}

@Bind(R.id.tv_value) TextView tv_value;

@Override
public void bindDropDownView(YourModel model, int position) {
tv_value.setText(model.getValue());
}

@Override
public void bindView(YourModel model, int position) {
tv_value.setText(model.getValue());
}
}

```

Now instantiate [OkSpinnerAdapter](https://github.com/FuckBoilerplate/OkAdapters/blob/master/library/src/main/java/library/spinner/OkSpinnerAdapter.java) using the previous `OkSpinnerAdapter.Binder` implementation class and use it as a normal `adapter`.

```java

List<YourModel> items = getItems();

OkSpinnerAdapter<YourModel, YourModelViewGroup> adapter = new OkSpinnerAdapter<YourModel, YourModelViewGroup>(context, items) {
@Override
public YourModelViewGroup inflateView() {
return new YourModelViewGroup(context);
}
};

spinner.setAdapter(adapter);

```

[Reference](https://github.com/FuckBoilerplate/OkAdapters/tree/master/app/src/main/java/app/recycler_view) to a complete example.

0 comments on commit af2b604

Please sign in to comment.