Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize a simple binary conversion Calculator with Android Studio

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the Android Studio how to achieve simple binary conversion calculator related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Android Studio how to achieve simple binary conversion calculator article will have a harvest, let's take a look at it.

1. Problem description

A number system converter is designed and implemented, which can convert the input value of any-base type to the value of the specified number system type. There are four types of number systems that must be implemented: binary, octal, decimal and hexadecimal.

2. Basic requirements

(1) use the Spinner control to list four types of number systems: binary, octal, decimal and hexadecimal.

(2) the "numeric" input box does not use the input panel provided by the Android system for numerical input, and can only be integer values.

Layout code:

Button pressing effect (btn_1.xml) code

Master Code (MainActivity)

Package com.example.hzljinzhi;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.EditText;import android.widget.Spinner;public class MainActivity extends AppCompatActivity {Spinner spinner1,spinner2; EditText et_shuru,et_shuchu; Button btn_CE,btn_js Int ids [] = {R.id.btny0repartedR.id.btnying2penceR.id.btnclass3penceR.id.btnclass4coveryR.id.btnwords 5, R.id.btnwords 6authorityR.id.btnwords 7, R.id.btnstories 8parentials R.id.btnstories 9parentsR.id.btnletters AmagedrrR.id.btnwriters R.id.btnletters R.id.btn_E,R.id.btn_F} String temp=null,num1=null,num2=null,num3=null,num4=null;int k; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); btn_CE=findViewById (R.id.btn_CE); btn_js=findViewById (R.id.btn_js) Btn_CE.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {et_shuru.setText ("); et_shuchu.setText (");}}); for (int iTunes parent) {}}); spinner2.setAdapter (adapter) Spinner2.setOnItemSelectedListener (new AdapterView.OnItemSelectedListener () {@ Override public void onItemSelected (AdapterView parent, View view, final int pos) Long id) {switch (pos) {case 0: btn_js.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {temp = et_shuru.getText () .toString () Num3 = Integer.valueOf (temp, k). ToString (); / / convert to decimal Num1 = Integer.toBinaryString (Integer.parseInt (num3)); et_shuchu.setText (num1);}}); break Case 1: btn_js.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {temp = et_shuru.getText () .toString (); num3 = Integer.valueOf (temp, k) .toString () / / convert to decimal Num2 = Integer.toOctalString (Integer.parseInt (num3)); et_shuchu.setText (num2);}}); break Case 2: btn_js.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {temp = et_shuru.getText () .toString (); num3 = Integer.valueOf (temp, k) .toString () / / convert to decimal Et_shuchu.setText (num3);}}); break Case 3: btn_js.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {temp = et_shuru.getText () .toString (); num3 = Integer.valueOf (temp, k) .toString (); / / convert to decimal Num4 = Integer.toHexString (Integer.parseInt (num3)); et_shuchu.setText (num4);}}); break;}} @ Override public void onNothingSelected (AdapterView parent) {}}) } public void setEnabled (int count) {int iTun0, size = Math.min (count,ids.length); for

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report