有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java按钮故障

当用户单击Next按钮时,它应该显示数据库中的下一个记录存储,但当我运行应用程序时,用户必须单击previous按钮查看下一个条目,而Next按钮没有执行任何活动

public void onClick(View v) {

        int buttonId = v.getId();

        if (buttonId == R.id.buttonViewPrevious)
            if (currentBoothArrayIndex < boothArrayList.size() - 1) {
                displayBoothInformation(--currentBoothArrayIndex);
            } else if (buttonId == R.id.buttonViewNext)
                if (currentBoothArrayIndex < boothArrayList.size() - 1) {
                    displayBoothInformation(++currentBoothArrayIndex);
                } 
    }

共 (1) 个答案

  1. # 1 楼答案

    你的if else构造是错误的。试试这个:

    if (buttonId == R.id.buttonViewPrevious){
       if (currentBoothArrayIndex < boothArrayList.size() - 1) {
         displayBoothInformation( currentBoothArrayIndex);
       } 
    }else if (buttonId == R.id.buttonViewNext){
       if (currentBoothArrayIndex < boothArrayList.size() - 1) {
         displayBoothInformation(++currentBoothArrayIndex);
       } 
    }