I'm going to use most common View Button for Setting onClick event :
Method One:- One Listener for One button:
Method Two:- Share One Listener with Multiple buttons:
Method Three:- Clicklistener bundled with an XML the layout of the Views element, Listener methods defined in the program with a View type of parameters as:
Method One:- One Listener for One button:
Button btn = (Button) findViewById(R.id.myButton); btn. SetOnClickListener (new View.OnClickListener() { Public void onClick(View v) the { // Do Something } });
Method Two:- Share One Listener with Multiple buttons:
Button btn = (Button)findViewById(R.id.mybutton); Button btn2 = (Button)findViewById(R.id.mybutton2); btn.setOnClickListener(handler); btn2.setOnClickListener(handler); View.OnClickListener handler = View.OnClickListener() { Public void onClick(View v) the { switch(v.getId()) { case R.id.mybutton: // Do Something break; case R.id.mybutton2: // Do Something break; } }
Method Three:- Clicklistener bundled with an XML the layout of the Views element, Listener methods defined in the program with a View type of parameters as:
Buttontst.Xml : java code:: Button btn = (Button) findViewById(R.id.mybutton); public void mybuttonlistener(View target){ //do something }
2 comments:
i need to get data from existing database that should be display on android device but iam trying
it is not displaying to my device
source can send to my mailid imrant24@gmail.com
Post a Comment