Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

princess mudyahoto
18,502 Pointstesting in android
Challenge Task 1 of 1
Here's a simple counter app consisting of only a TextView and a Button. When the Button is pressed the counter (TextView) increases by one.
Refactor this to now use a View and Presenter.
public class MainActivity extends AppCompatActivity {
TextView counter;
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int count = Integer.parseInt(counter.getText().toString());
counter.setText(Integer.toString(count + 1));
}
});
}
}
public interface MainActivityView {
void changeTextViewText(String text);
}
public class MainActivityPresenter {
MainActivityView view;
public MainActivityPresenter(MainActivityPresenter view) {
this.Presenterview.(view);
} // MainActivityPresenter()
public void buttonClicked(String text) {
view.changeTextViewText(text);
} // editTextUpdated()
}
1 Answer

Seth Kroger
56,407 PointsYou still need to implement the MainActivityView
interface in MainActivity.