Android Studio實(shí)現(xiàn)簡易進(jìn)制轉(zhuǎn)換計(jì)算器
本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)簡易進(jìn)制轉(zhuǎn)換計(jì)算器的具體代碼,供大家參考,具體內(nèi)容如下
1、問題描述
設(shè)計(jì)并實(shí)現(xiàn)一個(gè)數(shù)制轉(zhuǎn)換器,能夠?qū)斎氲娜? -進(jìn)制類型的數(shù)值轉(zhuǎn)換為指定的數(shù)制類型的數(shù)值。必須實(shí)現(xiàn)的數(shù)制類型有二進(jìn)制、八進(jìn)制、十進(jìn)制和十六進(jìn)制四種。
2、基本要求
(1)使用Spinner 控件,列出四種數(shù)制類型,即:二進(jìn)制、八進(jìn)制、十進(jìn)制和十六進(jìn)制;
(2)“數(shù)值”輸入框,不使用Android系統(tǒng)提供的輸入面板,進(jìn)行數(shù)值輸入;且只能是整數(shù)數(shù)值;
布局代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:orientation="vertical" ? ? > ? ? <TextView ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="進(jìn)制轉(zhuǎn)換器" ? ? ? ? android:textSize="35sp" ? ? ? ? android:textColor="#9900AA"/> ? ? <TextView ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="輸入數(shù)據(jù):" ? ? ? ? android:textSize="30sp" ? ? ? ? android:textColor="#99CCAA"/> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/tv_1" ? ? ? ? ? ? android:layout_width="125dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="進(jìn)制類型:" ? ? ? ? ? ? android:textSize="25sp" ? ? ? ? ? ? android:textColor="#000" ? ? ? ? ? ? /> ? ? ? ? <Spinner ? ? ? ? ? ? android:id="@+id/spinner1" ? ? ? ? ? ? android:layout_width="240dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:textSize="30sp" ? ? ? ? ? ? /> ? ? </LinearLayout> ? ? <EditText ? ? ? ? android:id="@+id/et_shuru" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"></EditText> ? ? <TextView ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="輸出數(shù)據(jù):" ? ? ? ? android:textSize="30sp" ? ? ? ? android:textColor="#99CCAA"/> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/tv_2" ? ? ? ? ? ? android:layout_width="125dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="進(jìn)制類型:" ? ? ? ? ? ? android:textSize="25sp" ? ? ? ? ? ? android:textColor="#000" ? ? ? ? ? ? /> ? ? ? ? <Spinner ? ? ? ? ? ? android:id="@+id/spinner2" ? ? ? ? ? ? android:layout_width="240dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:textSize="30sp" ? ? ? ? ? ? /> ? ? </LinearLayout> ? ? <EditText ? ? ? ? android:id="@+id/et_shuchu" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"></EditText> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? <Button ? ? ? ? android:id="@+id/btn_0" ? ? ? ? android:layout_width="70dp" ? ? ? ? android:layout_height="35dp" ? ? ? ? android:text="0" ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_1" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="1" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_2" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="2" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_3" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="3" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_4" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="4" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_5" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="5" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_6" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="6" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_7" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="7" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_8" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="8" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_9" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="9" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_A" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="A" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_B" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="B" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_C" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="C" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_D" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="D" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_E" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="E" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_F" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="F" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_CE" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="35dp" ? ? ? ? ? ? android:text="CE" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? ? ? <Button ? ? ? ? ? ? android:id="@+id/btn_js" ? ? ? ? ? ? android:layout_width="70dp" ? ? ? ? ? ? android:layout_height="40dp" ? ? ? ? ? ? android:text="計(jì)算" ? ? ? ? ? ? android:background="@drawable/btn_1" ? ? ? ? ? ? /> ? ? </LinearLayout> </LinearLayout>
按鈕按壓效果(btn_1.xml)代碼
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> ? ? <item android:state_pressed="true"> ? ? ? ? <shape> ? ? ? ? ? ? <solid android:color="#CC7A00"/> ? ? ? ? ? ? <corners android:radius="10dp"/> ? ? ? ? </shape> ? ? </item> ? ? <item android:state_pressed="false"> ? ? ? ? <shape> ? ? ? ? ? ? <solid android:color="#FF9900"/> ? ? ? ? ? ? <corners android:radius="10dp"/> ? ? ? ? </shape> ? ? </item> </selector>
主代碼(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.btn_0,R.id.btn_1,R.id.btn_2,R.id.btn_3,R.id.btn_4,R.id.btn_5, R.id.btn_6,R.id.btn_7,
? ? ? ? ? ? R.id.btn_8,R.id.btn_9,R.id.btn_A,R.id.btn_B,R.id.btn_C,R.id.btn_D,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 i=0;i<ids.length;i++){
? ? ? ? ? ? Button btn = findViewById(ids[i]);
? ? ? ? ? ? if(btn != null)
? ? ? ? ? ? ? ? btn.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? ? ? ? ? switch (v.getId()){
? ? ? ? ? ? ? ? ? ? ? ? ? ?case ?R.id.btn_0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"0");
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"1");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_2:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"2");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_3:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"3");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_4:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"4");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_5:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"5");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_6:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"6");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_7:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"7");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_8:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"8");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_9:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"9");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_A:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"A");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_B:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"B");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_C:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"C");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_D:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"D");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_E:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"E");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case ?R.id.btn_F:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuru.setText(et_shuru.getText()+"F");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? }
? ? ? ? et_shuru=findViewById(R.id.et_shuru);
? ? ? ? et_shuchu=findViewById(R.id.et_shuchu);
? ? ? ?spinner1=(Spinner)findViewById(R.id.spinner1);
? ? ? ?spinner2=(Spinner)findViewById(R.id.spinner2);
? ? ? ? //建立數(shù)據(jù)源
? ? ? ?String[] mltems = getResources().getStringArray(R.array.data);
? ? ? ? ArrayAdapter<String>adapter= new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,mltems);
? ? ? ? adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
? ? ? ? //綁定Adapter到控件
? ? ? ? spinner1.setAdapter(adapter);
? ? ? ? spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
? ? ? ? ? ? ? ? switch (pos){
? ? ? ? ? ? ? ? ? ? case 0: k=2;setEnabled(2);break;
? ? ? ? ? ? ? ? ? ? case 1: k=8;setEnabled(8);break;
? ? ? ? ? ? ? ? ? ? case 2: k=10;setEnabled(10);break;
? ? ? ? ? ? ? ? ? ? case 3: k=16;setEnabled(16);break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onNothingSelected(AdapterView<?> 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();//轉(zhuǎn)換為十進(jìn)制;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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();//轉(zhuǎn)換為十進(jìn)制;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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();//轉(zhuǎn)換為十進(jìn)制;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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();//轉(zhuǎn)換為十進(jìn)制;
? ? ? ? ? ? ? ? ? ? ? ? ? ? num4 = Integer.toHexString(Integer.parseInt(num3));
? ? ? ? ? ? ? ? ? ? ? ? ? ? et_shuchu.setText(num4);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? });break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onNothingSelected(AdapterView<?> parent) {
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? public void setEnabled(int count){
? ? ? ? int i =0,size = Math.min(count,ids.length);
? ? ? ? for( i=0;i<size;i++){
? ? ? ? ? ? Button btn = findViewById(ids[i]);
? ? ? ? ? ? if(btn != null){
? ? ? ? ? ? ? ? btn.setEnabled(true);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? for( i=size;i<ids.length;i++){
? ? ? ? ? ? Button btn = findViewById(ids[i]);
? ? ? ? ? ? if(btn != null){
? ? ? ? ? ? ? ? btn.setEnabled(false);
? ? ? ? ? ? }
? ? ? ? }
? ? }
}Spinner 控件的數(shù)據(jù)源(jinzhi.xml)
<?xml version="1.0" encoding="utf-8"?> <resources> ? ? <string-array name="data"> ? ? ? ? <item>二進(jìn)制</item> ? ? ? ? <item>八進(jìn)制</item> ? ? ? ? <item>十進(jìn)制</item> ? ? ? ? <item>十六進(jìn)制</item> ? ? </string-array> </resources>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android獲得當(dāng)前view在屏幕中坐標(biāo)的方法
這篇文章主要介紹了android獲得當(dāng)前view在屏幕中坐標(biāo)的方法,涉及Android針對view坐標(biāo)相關(guān)屬性的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Android Studio 升級到3.0 提示 java.lang.NoClassDefFoundError的解決方法
這篇文章主要介紹了Android Studio 升級到3.0 提示 java.lang.NoClassDefFoundError的解決方法,需要的朋友可以參考下2017-12-12
Android中使用Camera類編寫手機(jī)拍照App的實(shí)例教程
這篇文章主要介紹了Android中使用Camera類編寫手機(jī)拍照App的實(shí)例教程,整理了Camera調(diào)用硬件進(jìn)行拍照的一些常用方法,需要的朋友可以參考下2016-04-04
Android APP開發(fā)KML軌跡導(dǎo)出教程示例
這篇文章主要為大家介紹了Android APP開發(fā)KML軌跡導(dǎo)出教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
淺析Android手機(jī)衛(wèi)士讀取聯(lián)系人
這篇文章主要介紹了淺析Android手機(jī)衛(wèi)士讀取聯(lián)系人的相關(guān)內(nèi)容,通過getContentResolver()方法獲取獲取ContentResolver內(nèi)容解析器對象,對android手機(jī)衛(wèi)士讀取聯(lián)系人相關(guān)知識感興趣的朋友參考下吧2016-04-04
Android App中ListView仿QQ實(shí)現(xiàn)滑動(dòng)刪除效果的要點(diǎn)解析
這篇文章主要介紹了Android App中ListView仿QQ實(shí)現(xiàn)滑動(dòng)刪除效果的要點(diǎn)解析,重點(diǎn)是要判斷手勢按下的位置坐標(biāo),需要的朋友可以參考下2016-04-04
進(jìn)度條ProgressBar及ProgressDialog(實(shí)例)
下面小編就為大家?guī)硪黄M(jìn)度條ProgressBar及ProgressDialog(實(shí)例)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
Android 自定義View時(shí)使用TypedArray配置樣式屬性詳細(xì)介紹
這篇文章主要介紹了Android 自定義View時(shí)使用TypedArray配置樣式屬性詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-11-11
Android快速實(shí)現(xiàn)一個(gè)財(cái)務(wù)APP程序詳解
這篇文章主要介紹了Android實(shí)現(xiàn)的財(cái)務(wù)APP程序,結(jié)合前后端共功能完善,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07

