Current Version 2.2.0
- Clone a copy of the repo
$ git clone git://Rmanaf/com.divankits.mvc.git
-
Add module in your project
-
Create a model and assign view by using "@View" annotation
@View(R.layout.test_view)
public class TestModel extends Model {
public CharSequence Title = "Test"
public String Description;
...
}
- Create layout for model
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
...
- Bind view components to the model fields
@View(R.layout.test_view)
public class TestModel extends Model {
@Bind(value = R.id.title_txt , set = "setText" , converter = CharSequenceToStringValueConverter.class)
public String Title;
/* For custom components :
@Bind(value = R.id.title_txt , set = "method name" , get = "method name" , converter = <ValueConverter>.class)
public CharSequence Title;
*/
...
- Create a controller
public class TestController extends Controller {
public TestController() {
setModel(new TestModel())
}
}
- Add a FrameLayout in your main layout
...
<FrameLayout
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
...
- Add controller instance to activity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new TestController(this , R.id.placeholder);
}
}
For more information visit Wiki page
This project is licensed under the terms of the MIT license