按钮单击仅增加一个项目,即使我多次单击该按钮,也会停留在该项目上

时间:2018-03-08 07:55:40

标签: android android-layout onclick uibutton

当我点击next按钮时,我为我的应用实现了导航到下一个项目的方法。但由于某种原因,即使我在同一个屏幕上多次点击按钮,我的应用程序也只会增加position once并保持相同的项目。我的循环中是否有任何错误导致它只增加一次?

public int index_positionPlus;
public int index_positionMinus;
public String video_URL;
public long currentPosition;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle saveInstanceState) {
    final View rootView  = inflater.inflate(R.layout.rightside_video_fragment, parent, false);
    ButterKnife.bind(this, rootView);

    currentPosition = C.TIME_UNSET;
    if (saveInstanceState != null) {
        stepDataModels = getArguments().getParcelableArrayList("steps_list");
        mListIndex = saveInstanceState.getInt(ARG_POSITION);
        currentPosition = saveInstanceState.getLong("selected_position", C.TIME_UNSET);
    } else {
            stepDataModels = getArguments().getParcelableArrayList("steps_list");
    }

    if (stepDataModels != null) {
        recipeInstructions.setText(stepDataModels.get(mListIndex).getDescription().toString());
        video_URL = stepDataModels.get(mListIndex).getVideoURL().toString();
    }

    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(mListIndex >= 0 && mListIndex <= stepDataModels.size()) {
                index_positionPlus = mListIndex + 1;
                recipeInstructions.setText(stepDataModels.get(index_positionPlus).getDescription().toString());
                video_URL = stepDataModels.get(index_positionPlus).getVideoURL().toString();
            } else {
                recipeInstructions.setText(stepDataModels.get(mListIndex).getDescription().toString());
                video_URL = stepDataModels.get(mListIndex).getVideoURL().toString();
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

 index_positionPlus = 0;
进入全球。 每次调用该函数时,index_positionPlus都会重置为零。