java - Buttons not responding when pressing -
I'm new to Android development and I'm making a simple calculator. Everything is working fine and no errors are showing, but whenever I press them, the My goal SDK Main Activity. Java Can anyone see what I have done? BTNClock has not been started! Try it: button is not working.
API19: Android 4.4 (KitKat) and compiling with
API 20: Android 4.4 (KitKat Wear) . Here is my code,
package edu.shihank.mycalcv2; Import android.support.v7.app.ActionBarActivity; Importroid.os.Bundle; Import android.view.Menu; Import android.view.MenuItem; Import android.view.View; Import android.view.View.OnClickListener; Import android.widget.Button; Import android.widget.TextView; Public class main activity actionbusiness activity (public text TV); Public name numbBf; Public string operation; Public Button ClickList BTNClick; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_main); Tv = (TextView) findViewById (R.id.tv); Intuitist [] = {R. Dijorro, R.Did.On, R.Did.DO, R.Did.TH, R.D.For, R.Did, R.Id.I.S.I.C. , R. Id.seven, R.id.eight, R.id.nine, R.id.add, R.id.sub, R.id.div, R.id.Multi, R.id.equal, R.id. Clear, R.I.D. History}; For (integer id: idList) {see v = (see) findViewById (id); V.setOnClickListener (btnClick); }} @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Increase Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fluo (R. menu menu, menu); Back true; } @ Override Public Boolean On Option Itam Select (menu item) {// Handle action bar item here clicks the action bar will automatically click on the Home / Up button, so long as you // in AndroidManifest.xml Specify basic activity. Int id = item.getItemId (); If (id == R.id.action_settings) {return true; } Return Super.Options item selected (item); } Public Zero getKeyboard (string str) {string TVNow = tv.getText (). ToString (); TVNow + = str; Tv.setText (tvNow); } Public Zero Result () {Float numbAf = Float.parseFloat (tv.getText (). ToString ()); Float result = 0; If (operation.edge ("+")) {result = numbAf + numbBf; } If (operation.exls ("-")) {result = numbAf - numbBf; } If (operation.exe ("*")) {result = curb * numbBf; } If (operation.exls ("/")) {result = numbAf / numbBf; } Tv.setText (String.valueOf (results)); } Public zero theMath (string str) {numbBf = Float.parseFloat (tv.getText (). ToString ()); Operation = str; Tv.setText ("0"); } Private class applies ButtonClickListener OnClickListener {@Override Click Public Zero (see V) {Switch (v.getId ()) {Case R.id.clear: tv.setText ("0"); NumbBf = 0; Operation = ""; break; Case R.id.add: theMath ("+"); break; Case R.id.sub: theMath ("-"); break; Case R.id.div: theMath ("/"); break; Case R.D. Malty: The Math ("*"); break; Case R.id.equal: theResult (); break; Default: string number = ((button) v) .gettext (). ToString (); GetKeyboard (numb); break; }}}}
@ Override Protected Zero (Bundle Saved InstantState) {Super. SetContentView (R.layout.activity_main); Tv = (TextView) findViewById (R.id.tv); Intuitist [] = {R. Dijorro, R.Did.On, R.Did.DO, R.D.D.R., RID.For, R.DID, R.IDIICI, R. . Id.seven, R.id.eight, R.id.nine, R.id.add, R.id.sub, R.id.div, R.id.Multi, R.id.equal, R.id. Clear, R.I.D. History}; Btnclic = new buttonclicklist (); // To add this line (int id: idList) {see v = (see) findViewById (id); V.setOnClickListener (btnClick); }}
Comments
Post a Comment