这段代码中是否有我遗漏的东西? 是的,我知道这主要是代码,但恕我直言,我认为很清楚。 Stil似乎需要更多不必要的文本。
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
{
if(container == null) { return null; }
super.onCreateView(inflater, container, savedInstanceState);
final EditText editText = (EditText) outsideLayout.findViewById(R.id.prefPlayerName);
editText.setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_GO);
editText.setOnKeyListener(new EditText.OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// If the event is a key-down event on the "enter" key
if((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER))
{
Log.i(TAG, "PrefDetailsFragment enter key pressed");
return true;
}
return false;
}
});
return outsideLayout;
} // onCreateView()
答案 0 :(得分:-1)
尝试在editText
之外移动onCreateView
并在onResume
中设置监听器。您可能还想删除对super的调用,并在容器为null时退出。
@Override
protected void onResume() {
super.onResume();
if ( editText != null && ! editTexthasOnClickListeners() ) {
editText.setOnKeyListener( ... ); // Add on click listener here as well
}
}