Adding rows into Cursor manually

前端 未结 4 561
無奈伤痛
無奈伤痛 2020-12-03 13:47

I have an array of phone numbers and I want to get the corresponding contact names from the contacts database.

In the array of phone numbers, I also have some number

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 14:27

    I know this an old post, but it is a real pain that rows can not be added manually to a Cursor. I have come up with a crude solution. It might be of some help.

    Cursor is actually an interface and you can create a custom class that implements the Cursor interface.

    class ManualCursor implements Cursor{
          // ....
          private Vector rows;
    
          public void addRow(String[] values){
                rows.add(values);
          }
    
          // Implement the necessary methods, getString(int), etc.
    
          //....
    }
    

    And finally in your code

    if (cursors[i].getCount() == 0){
         cursors[i] = new ManualCursor();
         cursors[i].addRow(rowValues);
    }
    

    That should do it. But be warned though, for this to work, you have to be wise while implementing the Cursor interface.

提交回复
热议问题