Home>
final int [] location=new int [2];
view.getlocationonscreen (location);

In this way, you can get the x and y values ​​of the view in the global coordinate system.Which includes the height of the notification bar)

//Get the absolute coordinates in the current screen
location [0] x coordinate
location [1] y coordinate

Application, we can use to record the last time the listview scrolled there

First we need a global variable that records the current scroll position:

private float oldlisty=-1;

Then get oldlisty in the listite's onitemclick () or onitemlongclick () event:

lstview.setonitemclicklistener (new onitemclicklistener ()
{
  public void onitemclick (adapterview<?>arg0, view arg1, int arg2, long arg3)
  {
    int pos []={-1, -1};//Array holding current coordinates
    arg1.getlocationonscreen (pos);//Get the position of the selected item on the screen,Origin from top left corner (0, 0)
    oldlisty=(float) pos [1];//we just take the y coordinate
  }
});

The last thing to do is restore the previous position after setadapter ():

...
lstview.setadapter (adapter);//Rebind adapter
lstview.setselectionfromtop (index, (int) oldlisty);//restore the previous position
  • Previous VC method of accessing database based on ADO technology
  • Next C language fillpoly function