Posts

Showing posts with the label Model View Controller

Android How Do I Correctly Get The Value From A Switch?

Answer : Switch s = (Switch) findViewById(R.id.SwitchID); if (s != null) { s.setOnCheckedChangeListener(this); } /* ... */ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Toast.makeText(this, "The Switch is " + (isChecked ? "on" : "off"), Toast.LENGTH_SHORT).show(); if(isChecked) { //do stuff when Switch is ON } else { //do stuff when Switch if OFF } } Hint: isChecked is the new switch value [ true or false ] not the old one. Since it extends from CompoundButton (docs), you can use setOnCheckedChangeListener() to listen for changes; use isChecked() to get the current state of the button. Switch switch = (Switch) findViewById(R.id.Switch2); switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ...

Business Logic In MVC

Answer : Fist of all: I believe that you are mixing up the MVC pattern and n-tier-based design principles. Using an MVC approach does not mean that you shouldn't layer your application. It might help if you see MVC more like an extension of the presentation layer. If you put non-presentation code inside the MVC pattern you might very soon end up in a complicated design. Therefore I would suggest that you put your business logic into a separate business layer. Just have a look at this: Wikipedia article about multitier architecture It says: Today, MVC and similar model-view-presenter (MVP) are Separation of Concerns design patterns that apply exclusively to the presentation layer of a larger system. Anyway ... when talking about an enterprise web application the calls from the UI to the business logic layer should be placed inside the (presentation) controller. That is because the controller actually handles the calls to a specific resource, queries the data by...