Android : onCreateView() - Cannot make a static reference to the non-static method

on Sunday, February 15, 2015


I am trying to close soft keyboard after entering some text on a field. This is the code I have on my Fragment's onCreateView(). However, I get the following errors:



Cannot make a static reference to the non-static method getWindow() from the type Activity
Cannot make a static reference to the non-static method getSystemService(String) from the type Activity


Any ideas?



public class SignInActivity extends ActionBarActivity {

[...]


/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_sign_in,
container, false);

getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

EditText phone =
(EditText)getView().findViewById(R.id.input_field);
phone.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

in.hideSoftInputFromWindow(((TextView) v.getWindowToken()).getApplicationWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
return true;

}
return false;
}
});

return rootView;
}
}
}

0 comments:

Post a Comment