Source:
<code><START> private void initDrawer() <END> { final View drawer = findViewById(R.id.drawer); final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); actions = findViewById(R.id.actions); actions.setSelected(true); actions.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(! actions.isSelected()) { replaceCurrentFragment(ActionsFragment.newInstance(), ActionsFragment.TAG); drawerLayout.closeDrawer(drawer); } } }); hub = findViewById(R.id.hub); hub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(! hub.isSelected()) { replaceCurrentFragment(newInstance(false), TAG); drawerLayout.closeDrawer(drawer); } } }); invites = findViewById(R.id.invites); invites.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(! invites.isSelected()) { replaceCurrentFragment(InvitesFragment.newInstance(), InvitesFragment.TAG); drawerLayout.closeDrawer(drawer); } } }); notifications = findViewById(R.id.notifications); notifications.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(! notifications.isSelected()) { replaceCurrentFragment(NotificationsFragment.newInstance(), NotificationsFragment.TAG); drawerLayout.closeDrawer(drawer); } } }); View setting = findViewById(R.id.setting); setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(SettingsActivity.getLaunchIntent(MainActivity.this)); drawerLayout.closeDrawer(drawer); } }); }</code><technical_language>TODO drawer a list view, need this redundant logic</technical_language>

Target:
private void initDrawer() { final String[] list = getResources().getStringArray(R.array.drawer_list); final View drawer = findViewById(R.id.drawer); final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); final ListView listView = (ListView) findViewById(R.id.menu_list); listView.setAdapter(new DrawerListAdapter(this, list)); listView.setItemChecked(0, true); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String positionString = list[position]; if(TextUtils.equals(positionString, getString(R.string.actions))) { replaceCurrentFragment(ActionsFragment.newInstance(), ActionsFragment.TAG); } else if(TextUtils.equals(positionString, getString(R.string.hub))) { replaceCurrentFragment(HubFragment.newInstance(false), HubFragment.TAG); } else if(TextUtils.equals(positionString, getString(R.string.invites))) { replaceCurrentFragment(InvitesFragment.newInstance(), InvitesFragment.TAG); } else if(TextUtils.equals(positionString, getString(R.string.notifications))) { replaceCurrentFragment(NotificationsFragment.newInstance(), NotificationsFragment.TAG); } drawerLayout.closeDrawer(drawer); } }); View setting = findViewById(R.id.setting); setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(SettingsActivity.getLaunchIntent(MainActivity.this)); drawerLayout.closeDrawer(drawer); } }); if(AppPrefs.getInstance(this).isFirstDrawer()) { AppPrefs.getInstance(this).setFirstDrawer(); drawerLayout.openDrawer(drawer); } }