高尔夫应用:
我有一个带有9个片段(洞)的标签式活动
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
switch(position){
case 0: return HoleFragment.newInstance("1","3", "160", "hole1");
case 1 : return HoleFragment.newInstance("2","3", "160m", "hole2");
case 2 : return HoleFragment.newInstance("3","3", "125m", "hole3");
case 3 : return HoleFragment.newInstance("4","3", "90m", "hole4");
case 4 : return HoleFragment.newInstance("5","3", "150m", "hole5");
case 5 : return HoleFragment.newInstance("6","3", "155", "hole6");
case 6 : return HoleFragment.newInstance("7","3", "80m", "hole7");
case 7 : return HoleFragment.newInstance("8","3", "150m", "hole8");
case 8 : return HoleFragment.newInstance("9","3", "120m", "hole9");
}
return null;
}
@Override
public int getCount() {
return 9;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "SECTION 1";
case 1:
return "SECTION 2";
case 2:
return "SECTION 3";
}
return null;
}
}
每个洞都适应:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_hole, container, false);
holeText = (TextView) v.findViewById(R.id.holeText);
holeText.setText(mParam1);
parText = (TextView) v.findViewById(R.id.parText);
parText.setText(mParam2);
distanceText = (TextView) v.findViewById(R.id.distanceText);
distanceText.setText(mParam3);
carte = (ImageView) v.findViewById(R.id.imageViewCarte);
Resources res = getResources();
if(mParam4.equals("hole9")){
Button myButton = new Button(getActivity());
myButton.setText("Fin");
myButton.setHeight(30);
LinearLayout ll = (LinearLayout) v.findViewById(R.id.button_end_layout);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ll.addView(myButton, lp);
}
String mDrawableName = mParam4;
System.out.println(mDrawableName);
int resID = res.getIdentifier(mDrawableName , "drawable", getActivity().getPackageName());
System.out.println(resID);
carte.setImageResource(resID);
return v;
}
正如你所看到的,我动态地添加了一个" End"第9洞的按钮。我想要做的是在单击结束按钮时,在每个片段中的EditText中输入所有分数。
有什么想法吗?