How to attach onItemSelectedListener to WearableNavigationDrawerView?
up vote
0
down vote
favorite
I have implemented a NavigationDrawer, but in the NavigationAdapter, the onItemSelected
method is not running. I'm guessing that attaching a listener to somewhere is missing. I think the MainActivity
class has every part to it, I just can't figure out where and how to add an onItemSelectedListener.
public class MainActivity extends WearableActivity
private WearableNavigationDrawerView mWearableNavigationDrawer;
private static final SectionFragment.Section DEFAULT_SECTION = SectionFragment.Section.Main;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_navigation_drawer);
mWearableNavigationDrawer.setAdapter(new NavigationAdapter(this));
mWearableNavigationDrawer.getController().peekDrawer();
private final class NavigationAdapter
extends WearableNavigationDrawerView.WearableNavigationDrawerAdapter implements WearableNavigationDrawerView.OnItemSelectedListener
private final Context mContext;
private SectionFragment.Section mCurrentSection = DEFAULT_SECTION;
NavigationAdapter(final Context context)
mContext = context;
@Override
public String getItemText(int index)
return mContext.getString(SectionFragment.Section.values()[index].titleRes);
@Override
public Drawable getItemDrawable(int index)
return mContext.getDrawable(SectionFragment.Section.values()[index].drawableRes);
@Override
public void onItemSelected(int pos)
SectionFragment.Section selectedSection = SectionFragment.Section.values()[pos];
// Only replace the fragment if the section is changing.
if (selectedSection == SectionFragment.Section.Main)
setContentView(R.layout.activity_main);
else
setContentView(R.layout.activity_alarm);
mCurrentSection = selectedSection;
@Override
public int getCount()
return SectionFragment.Section.values().length;
android wear-os
add a comment |
up vote
0
down vote
favorite
I have implemented a NavigationDrawer, but in the NavigationAdapter, the onItemSelected
method is not running. I'm guessing that attaching a listener to somewhere is missing. I think the MainActivity
class has every part to it, I just can't figure out where and how to add an onItemSelectedListener.
public class MainActivity extends WearableActivity
private WearableNavigationDrawerView mWearableNavigationDrawer;
private static final SectionFragment.Section DEFAULT_SECTION = SectionFragment.Section.Main;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_navigation_drawer);
mWearableNavigationDrawer.setAdapter(new NavigationAdapter(this));
mWearableNavigationDrawer.getController().peekDrawer();
private final class NavigationAdapter
extends WearableNavigationDrawerView.WearableNavigationDrawerAdapter implements WearableNavigationDrawerView.OnItemSelectedListener
private final Context mContext;
private SectionFragment.Section mCurrentSection = DEFAULT_SECTION;
NavigationAdapter(final Context context)
mContext = context;
@Override
public String getItemText(int index)
return mContext.getString(SectionFragment.Section.values()[index].titleRes);
@Override
public Drawable getItemDrawable(int index)
return mContext.getDrawable(SectionFragment.Section.values()[index].drawableRes);
@Override
public void onItemSelected(int pos)
SectionFragment.Section selectedSection = SectionFragment.Section.values()[pos];
// Only replace the fragment if the section is changing.
if (selectedSection == SectionFragment.Section.Main)
setContentView(R.layout.activity_main);
else
setContentView(R.layout.activity_alarm);
mCurrentSection = selectedSection;
@Override
public int getCount()
return SectionFragment.Section.values().length;
android wear-os
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have implemented a NavigationDrawer, but in the NavigationAdapter, the onItemSelected
method is not running. I'm guessing that attaching a listener to somewhere is missing. I think the MainActivity
class has every part to it, I just can't figure out where and how to add an onItemSelectedListener.
public class MainActivity extends WearableActivity
private WearableNavigationDrawerView mWearableNavigationDrawer;
private static final SectionFragment.Section DEFAULT_SECTION = SectionFragment.Section.Main;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_navigation_drawer);
mWearableNavigationDrawer.setAdapter(new NavigationAdapter(this));
mWearableNavigationDrawer.getController().peekDrawer();
private final class NavigationAdapter
extends WearableNavigationDrawerView.WearableNavigationDrawerAdapter implements WearableNavigationDrawerView.OnItemSelectedListener
private final Context mContext;
private SectionFragment.Section mCurrentSection = DEFAULT_SECTION;
NavigationAdapter(final Context context)
mContext = context;
@Override
public String getItemText(int index)
return mContext.getString(SectionFragment.Section.values()[index].titleRes);
@Override
public Drawable getItemDrawable(int index)
return mContext.getDrawable(SectionFragment.Section.values()[index].drawableRes);
@Override
public void onItemSelected(int pos)
SectionFragment.Section selectedSection = SectionFragment.Section.values()[pos];
// Only replace the fragment if the section is changing.
if (selectedSection == SectionFragment.Section.Main)
setContentView(R.layout.activity_main);
else
setContentView(R.layout.activity_alarm);
mCurrentSection = selectedSection;
@Override
public int getCount()
return SectionFragment.Section.values().length;
android wear-os
I have implemented a NavigationDrawer, but in the NavigationAdapter, the onItemSelected
method is not running. I'm guessing that attaching a listener to somewhere is missing. I think the MainActivity
class has every part to it, I just can't figure out where and how to add an onItemSelectedListener.
public class MainActivity extends WearableActivity
private WearableNavigationDrawerView mWearableNavigationDrawer;
private static final SectionFragment.Section DEFAULT_SECTION = SectionFragment.Section.Main;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_navigation_drawer);
mWearableNavigationDrawer.setAdapter(new NavigationAdapter(this));
mWearableNavigationDrawer.getController().peekDrawer();
private final class NavigationAdapter
extends WearableNavigationDrawerView.WearableNavigationDrawerAdapter implements WearableNavigationDrawerView.OnItemSelectedListener
private final Context mContext;
private SectionFragment.Section mCurrentSection = DEFAULT_SECTION;
NavigationAdapter(final Context context)
mContext = context;
@Override
public String getItemText(int index)
return mContext.getString(SectionFragment.Section.values()[index].titleRes);
@Override
public Drawable getItemDrawable(int index)
return mContext.getDrawable(SectionFragment.Section.values()[index].drawableRes);
@Override
public void onItemSelected(int pos)
SectionFragment.Section selectedSection = SectionFragment.Section.values()[pos];
// Only replace the fragment if the section is changing.
if (selectedSection == SectionFragment.Section.Main)
setContentView(R.layout.activity_main);
else
setContentView(R.layout.activity_alarm);
mCurrentSection = selectedSection;
@Override
public int getCount()
return SectionFragment.Section.values().length;
android wear-os
android wear-os
asked Nov 9 at 9:47
adamb
124110
124110
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223326%2fhow-to-attach-onitemselectedlistener-to-wearablenavigationdrawerview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown