java


Click on button call item


When you click the button. I want an item to be called and executed
my xml file:
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:title="Item"
android:id="#+id/nav1" />
<item android:title="Item"
android:id="#+id/nav2"/>
</group>
</menu>
my simple menu item:
#Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav1) {
} else if (id == R.id.nav2) {
}
my button:
final Button button1 = (Button) findViewById(R.id.mybutton);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//when click on this button i want executed item with id nave1
}
});
when click on the button (mybutton) must call item and executed it
Use NavigationView.setCheckedItem()
final Button button1 = (Button) findViewById(R.id.mybutton);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
navigationView.setCheckedItem(R.id.nav1);
}
});
Or call onNavigationItemSelected() yourself.
final Button button1 = (Button) findViewById(R.id.mybutton);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
onNavigationItemSelected(navigationView.getMenu().findItem(R.id.nav1));
}
});
Its simple you can do it this way,create a method then call it anywhere u want.
private void yourMethodName() {
// do your stuff here
}
No call this
#Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav1) {
yourMethodName();
} else if (id == R.id.nav2) {
}
and then in button click ,
final Button button1 = (Button) findViewById(R.id.mybutton);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
yourMethodName();
}
});

Related Links

Multiply table insert using JDBC
Loop between two large numbers in few minutes [closed]
Cannot populate my ListView
OCR Tesseract did not call through super.OnCreate() even though it is
#ExceptionHandler doesn't catch exceptions being thrown from Spring Formatters
LOCAL_MODULE_FILENAME should not include file extensions i get this error each time i run ndk-build in terminal
Angular2 parse java.util.Date
How to give accurate Firebase reference?
Bypass selecting route, pressing “Start Navigation”, and updating destination during navigation
Jersey ServletContainer Hangs when logging errors in Errors.logErrors
Cannot find web elements at “chrome://downloads/” page
Datafile transfer between two folder with certain condition
HTTP 401 exception while using GET method of JIRA REST API from Java Code
WARN Exception in thread “Craft Scheduler Thread - 4”
Apache Camel CXF does not find the CXFEndpoint
Regex calendar validation

Categories

HOME
ms-access
client
asp.net-core
c#-4.0
tizen
heroku
push-notification
dictionary
kde
view
hashmap
alfresco
android-4.4-kitkat
framework7
bookshelf.js
yarn
amazon-ecs
frameworks
ravendb
constraint-programming
ssl-client-authentication
midi
floating-action-button
mapserver
circular-dependency
vb.net-2010
gz
ibm-odm
iron-router
iolanguage
workload-scheduler
http-status-code-504
database-replication
swiftlint
amazonsellercentral
physics-engine
jquery-ajaxq
functional-testing
emgucv
info.plist
ping
skia
create-table
protovis
repo
hot-module-replacement
swift3.0.2
event-driven
cookiecutter-django
ensembles
ruby-on-rails-3.1
gulp-sourcemaps
nand2tetris
no-www
angular2-meteor
user-accounts
appcompat
youcompleteme
chain-builder
promela
worksheet
fancybox-2
drupal-6
csound
windows-mobile-6.5
watchconnectivity
nxt
holder.js
unity-networking
separator
t4mvc
feedback
cakephp-3.1
processmodel
sniffer
mmc
composite
c3
camanjs
relocation
websocket4net
rdl
onactivityresult
article
xceed-datagrid
cloud-connect
stxxl
uv-mapping
tidy
blending
pushbackinputstream
smtp-auth
android-hardware
typoscript2
labwindows
objective-c-2.0
assembly-loading
qt-jambi
data-loss
iphone-web-app
mongomapper
h.323
paster
jquery-ui-droppable
dbal
castle-monorail
meego
zend-tool
javap
ajax-forms

Resources

Encrypt Message