Hey, I have touched on this question here, where Christopher gave an answer to this, but I dont really get it so I thought its time to make it a real question, not just a "follow up" =)
As it stands, the application Im writing has 4 different screens: 1. Screen 1 - list of nodes (main screen) 2. Screen 2 - options menu, tableLayout with buttons 3. Screen 3 - navigation 4. Screen 4 - text details on version etc
These screens can be navigated to/from using a "header" View that is placed on top. the header then has 4 different buttons:
+--------------------+
| menu with buttons |
+--------------------+
| |
| |
| |
| C O N T E N T |
| |
| |
| |
+--------------------+
The header is just an XML-file (header.xml) with a few buttons. That header.xml is the included in the Layouts using the include-markup. For example, the main.xml has the line:
<include layout="@layout/header"></include>
The header show up alright, but the question is - what is the correct approach to attach OnClickListeners for the buttons in the header?
Christopher pointed out that you could create an Activity class and do the hooks there, like this:
public class BaseActivity extends Activity {
protected View.OnClickListener mButtonListener;
protected void setupHeaderButtons() {
findViewById(R.id.header_btn_1).setOnClickListener(mButtonListener);
// ...
findViewById(R.id.header_btn_n).setOnClickListener(mButtonListener);
}
}
public class FirstActivity extends BaseActivity {
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.first_activity);
// This needs to be done *after* the View has been inflated
setupHeaderButtons();
}
}
First, I cant make it work since the method setupHeaderButtons isnt accessible from FirstActivity. Secondly, is this the right way to go at it?
Regards