我使用列表视图有问题,我用它来存储数据库内容



在我的应用程序中使用了简单的列表视图,用于显示数据库中的字符串内容。

如果我单击下一个项目,我有一个按钮,下一个将用一些颜色突出显示,它正在工作,但问题是如果项目超过 7 个项目,然后单击"下一步"按钮强制关闭。问题出在哪里。请给我解决它的想法。

编辑:

我使用简单的列表视图在其上显示项目,这是因为列表视图到达列表视图的末尾(底部)还是其他问题?你能告诉我我遇到了这个问题有什么问题吗?

我的代码是"下一步"按钮:

else if(v.getId()==R.id.buttonBookmarkrNext)
    {
        if((pos+1) == length)
        {   
            //if no of files exist in a arraylist and current position of a file matches do the following
            pos = 0;
            audiofile=(String) lv.getItemAtPosition(pos);
            Toast.makeText(this, " next file1",Toast.LENGTH_SHORT).show();
            lv.getChildAt(length-1).setBackgroundColor(0x00000000);
            lv.getChildAt(pos).setBackgroundColor(Color.LTGRAY);
        }
        else if(pos<length)
        {
            //if no of files exist in a arraylist(lenght) are greater than current position(pos) of a file  do the following
            pos ++;
            //audioDetails = (ArrayList<String[]>) lv.getItemAtPosition(pos);
            audiofile=(String) lv.getItemAtPosition(pos);
            Toast.makeText(this, " next file",Toast.LENGTH_SHORT).show();
            lv.getChildAt(pos-1).setBackgroundColor(0x00000000);
            lv.getChildAt(pos).setBackgroundColor(Color.LTGRAY);
            String str=(String) lv.getItemAtPosition(pos);
            //Log.e("next file end",str);
            Toast.makeText(this, " end file"+str,Toast.LENGTH_SHORT).show();
        }
    }

你的问题就在这里...

else if(pos<length)    // pos should be less than length-1, 
        {
            pos ++;
        .......
        .......
        }

试试这种方式...

else if(pos<(length-1))     
        {
            pos ++;
        .......
        .......
        }

相关内容

最新更新