Monday, April 11, 2011

Set Scroll position of a listview

Requirement :

Doesn't change the scroll position even if some list items are added to Listview dynamically.

problem faced : Scroll moving to first after listitems are added.

Solution:
// save index and top position
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();

// ...

// restore
mList.setSelectionFromTop(index, top);


Ref:

http://stackoverflow.com/questions/3014089/scroll-to-a-position-in-a-listview

Thursday, April 7, 2011

Disable BackButton (Escape) and Default MenuItems in Blackberry

While implementing loader screen on network call, i faced a problem with back button(escape) on the device which removes the loader screen from the stack resulting in unexpected results.So i override the keychar method
 
protected boolean keyChar(char arg0, int arg1, int arg2) {
   
      if(arg0 == Keypad.KEY_ESCAPE ){
        return true;
      }else
        return super.keyChar(arg0, arg1, arg1);
 };


I still faced an issue loader screen closing on Blackberry button press.

So i overrided the onMenu method as

public boolean onMenu(int instance) {
  
   if(instance==1073741824)
     return super.onMenu(instance);

  //returning false to intimate menu is not created
  return false;
}


Finally solved...