0

这段代码有什么我遗漏的吗?是的,我知道这主要是代码,但恕我直言,我认为这很清楚。仍然需要更多不必要的文本。

    @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()
4

1 回答 1

-1

尝试移出editTextonCreateView设置听者onResume。您可能还想删除对 super 的调用并在容器为空时退出。

@Override
protected void onResume() {
    super.onResume();
    if ( editText != null && ! editTexthasOnClickListeners() ) {
        editText.setOnKeyListener( ... );   // Add on click listener here as well
    }
}
于 2013-09-16T16:10:40.870 回答