Android 高尔夫应用程序,包含9个片段的活动,获得分数?

Android 高尔夫应用程序,包含9个片段的活动,获得分数?,android,android-fragments,Android,Android Fragments,高尔夫应用程序: 我有一个带有9个片段(孔)的选项卡式活动 每个孔都经过调整: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R

高尔夫应用程序:

我有一个带有9个片段(孔)的选项卡式活动

每个孔都经过调整:

@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;
}
如你所见,我在第9洞动态添加了一个“结束”按钮。我想做的是,当单击结束按钮时,获取每个片段中在EditText中输入的所有分数

有什么想法吗


您可以在承载此选项卡布局的活动中维护字符串或整数列表(用于存储分数)。您可以使用Interface,或者我建议使用Eventbus:将分数数据从孔碎片传递到托管活动。但是,使用Interface,我在单击按钮时调用Interface方法,但我只能访问第9个碎片分数..?每次更改viewpager页面时,您都可以调用该接口。
@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;
}