After filter a listview,how can I obtain the position of the first listview?

后端 未结 2 1761
生来不讨喜
生来不讨喜 2021-01-07 15:57

After filter a listview,how can I obtain the position of the first listview? I use simpleadapter to fill the listview. Each item in the datasource has its own id,and I use

相关标签:
2条回答
  • 2021-01-07 16:16

    this happens becouse Android gives you only IDs for the itmes you currently see + maybe two hidden on button and two hidden on top.

    In this tutorial you can see how to create a ListView with a model, this helps me, when i got this problem before. Add this to you code and change it (I think you don't need the checkboxes).

    0 讨论(0)
  • 2021-01-07 16:24

    I slove it with three arrays. Only test code:

    String positionString[]=new String[22];
                    int latterPosition[]=new int[22];
                    for (int i = 0; i < latterPosition.length; i++) {
                        positionString[i]="";
                        latterPosition[i]=0;
                    }
                    int latterCount=0;
                    for (int i = 0; i < positions.length; i++) {
                        if (positions[i]==10) {
                            positionString[latterCount]=i+"";
                            latterPosition[latterCount]=10;
                            latterCount++;
                        }
                    }
    
    0 讨论(0)
提交回复
热议问题