Search code examples
androidandroid-layoutandroid-activitycode-reuse

How can I reuse the Activity code?


We can use <include /> to include a layout into another.

I'm including activity_main.xml into activity_second.xml using <include />.

activity_main.xml has a <TextView /> and a <Button />. And the <Button /> has a handler doThis(View v){..} in MainActivity.java

How do I reuse the Button Handler in the SecondActivity.java


Solution

  • You can use Fragments for that