My a开发者_开发技巧pplication consists of a tab layout with six tabs. Each tab represents a player in a game.
I would like the activities within each tab to contain the exact same XML layout and code as the activities in the other tabs. Each player will get access to the same widgets and input fields.
Is there a way to write one activity and have each tab use that activity as a template? I am trying to avoid copying the code for the six activities.
Why not just create a parent activity to setcontentview(int resourceId,). That way you can write all the shared code inside the parent and just set all of your activities to extend your parent.
Parent Class:
public class ParentActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sharedLayoutFile);
}
}
All Other Activities
public class AllActivities extends ParentActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
...and more code for other stuff like linking data to UI, which
could be done in the parent if it is a standard data format.
}
}
I am not a java expert or an andorid expert but I would make a master activity and all the sub activites use a referance or a pointer to look at the main activy there for u will have a total of 7 but 6 of them will assable there data based on the pointer of the first one so if the first one changes the others ones change also.
精彩评论