0

I am working on android Version 8 and my emulator 2.2 I have tabview with Activity group, and multi childs and they are all listview but one is Activity the onbackPressed method is not working for the List Activity I have searcged and i found this code

@Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && CatalogGroup.group != null) {
       CatalogGroup.group.popView();
       return true;
   }
   return super.onKeyDown(keyCode, event);
 }

the problem is popView() is undefined in the type Group Activity and this is my Code

public class TabsGroup extends ActivityGroup {
public static TabsGroup group;
// additional Code
}

and this is the back Code

public void back() {
    if(history.size() > 0) {
        history.remove(history.size()-1);
        if (history.size() > 0)
            setContentView(history.get(history.size()-1));
    }else {
        finish();
    }
}

   public void onBackPressed() {
   CatalogGroup.group.back();
    return;
}

How could I make the back button works for the ListView ?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
omnia Mm
  • 157
  • 5
  • 16

1 Answers1

0

You should override the onKeyDown yourself like:

public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode==KeyEvent.KEYCODE_BACK) {
        // Your stuff
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50