In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Android how to achieve a simple calculator, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The details are as follows
Function
1. Four operations of addition, subtraction, multiplication and division
2. Return to 0
3. Fallback
4. real-time operation
Configuration
Add the following code to build.gradle (app)
BuildFeatures {viewBinding = true}
The location to join is as follows
CompileOptions {sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8} buildFeatures {viewBinding = true}
Overall Arrangement
Code
Public class MainActivity extends AppCompatActivity implements View.OnClickListener {private String tv= "0"; private ActivityMainBinding inflate; private String count= ""; private boolean isMax=false; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); inflate = ActivityMainBinding.inflate (getLayoutInflater ()); setContentView (inflate.getRoot ()); inflate.zero.setOnClickListener (this); inflate.yi.setOnClickListener (this); inflate.er.setOnClickListener (this) Inflate.san.setOnClickListener (this); inflate.si.setOnClickListener (this); inflate.wu.setOnClickListener (this); inflate.liu.setOnClickListener (this); inflate.qi.setOnClickListener (this); inflate.ba.setOnClickListener (this); inflate.jiu.setOnClickListener (this); inflate.add.setOnClickListener (this); inflate.sub.setOnClickListener (this); inflate.mul.setOnClickListener (this) Inflate.div.setOnClickListener (this); inflate.point.setOnClickListener (this); inflate.equal.setOnClickListener (this); inflate.dec.setOnClickListener (this); inflate.ac.setOnClickListener (this);} private void jisuanqi () {List strs=new ArrayList (); StringBuilder f = new StringBuilder (); for (int iTun0) I1) {tv= tv.substring (0, tv.length ()-1);} else {tv= "0";} jisuanqi (); break Case R.id.equal: if (! String.valueOf (tv.charAt (tv.length ()-1)). Matches ("(\ d +)") {tv= tv.substring (0, tv.length ()-1);} count=tv; jisuanqi (); tv=count Inflate.tv.setText (tv); break;} Thank you for reading this article carefully. I hope the article "how to implement a simple Calculator in Android" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.