0

I am trying to @Override onConfigurationChanged because I want to know when the keyboard down and when it is up but nothing happened.

What can I do? This is my source:

 @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      // Checks whether a hardware keyboard is available
      if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
          Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
      } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
          Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
      }
  }

I also added to the manifest this line

android:configChanges="keyboard|keyboardHidden"     
BenMorel
  • 34,448
  • 50
  • 182
  • 322
bar
  • 1
  • 1

1 Answers1

0

Try comparing newConfig.keyboardHidden==Configuration.KEYBOARDHIDDEN_YES This applies for all the keyboards whether it is attached to the device or not.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • it is not even reach the if else statement – bar Jul 24 '11 at 12:39
  • Make sure it reaches the onCnfgChngd() – Nikola Despotoski Jul 24 '11 at 12:45
  • http://stackoverflow.com/questions/2150078/android-is-software-keyboard-shown take a look at this question. You can do this also with measuring the layout. – Nikola Despotoski Jul 24 '11 at 12:47
  • `InputMethodManager imm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)); if(imm.isActive())` with this you can also check if the keyboard is active since, if any of the view is active for input means the keyboard is shown. – Nikola Despotoski Jul 24 '11 at 12:51
  • 10x bro , i will try this two options – bar Jul 24 '11 at 13:00
  • when i try this link stackoverflow.com/questions/2150078/… , i get exception ::: java.lang.ClassCastException: android.widget.LinearLayout – bar Jul 24 '11 at 13:29
  • where i need to put this code ?? i want to know every time that the keyboard shown and hide ? – bar Jul 24 '11 at 14:06
  • For the second one you put it in onConfgChngd(). For the 1st one(link) do it as it is shown. – Nikola Despotoski Jul 24 '11 at 14:09
  • the first one cause exception ... the second does not even get to the onConfgChngd() this was my only problem from the beginning how can i fix it ? – bar Jul 24 '11 at 14:14
  • i just want onConfgChngd() to work it will solve all my problems :-) – bar Jul 24 '11 at 14:20
  • `android:configChanges="keyboardHidden" ` try only with this, for detecting the appeariance of the keyboard. Add in onConfgChngd() `Log.i("onConfigChange()", "Success");` to check if it inside oCC() and check the logcat – Nikola Despotoski Jul 24 '11 at 14:23
  • public void onConfigurationChanged(Configuration newConfig) { Log.i("onConfigChange()", "Success"); super.onConfigurationChanged(newConfig); //Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show(); // Checks whether a hardware keyboard is available if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show(); } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) { } } – bar Jul 24 '11 at 14:33
  • Below super.onConfigurationChanged(newConfig) add the log.i() – Nikola Despotoski Jul 24 '11 at 14:39
  • If that does not work, then you should find the way with the 1st one (link). Modify it by your needs. – Nikola Despotoski Jul 24 '11 at 14:46
  • yessssss it's work , it is so funny the problem was that the class name was very long and the eclipse get exception or just collapsed. 10x bro – bar Jul 25 '11 at 07:53