Java Code Examples for android.widget.LinearLayout.setFocusableInTouchMode()

The following are Jave code examples for showing how to use setFocusableInTouchMode() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: planetcon   File: ListPlayersPreference.java   View Source Code Vote up 5 votes
@Override
protected View onCreateDialogView() {
    int numPlayers = mPrefs.getInt(SettingsActivity.KEY_PLAYERS_LIST, SettingsActivity.DEF_PLAYERS_LIST);
    ListView listPlayers = new ListView(mContext);
    listPlayers.setAdapter(mListAdapter);
    mListAdapter.setCount(numPlayers);

    // Needed to show the keyboard when a editText inside the listView is focused
    listPlayers.post(new Runnable() {
        @Override
        public void run() {
            Window window = getDialog().getWindow();
            if (window != null) {
                window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            }
        }
    });

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout linearLayout = new LinearLayout(mContext);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    // Needed to avoid autofocus of editText views
    linearLayout.setFocusableInTouchMode(true);
    linearLayout.addView(listPlayers, layoutParams);

    return linearLayout;
}