Android Studio實現(xiàn)簡易進制轉(zhuǎn)換計算器
本文實例為大家分享了Android Studio實現(xiàn)簡易進制轉(zhuǎn)換計算器的具體代碼,供大家參考,具體內(nèi)容如下
1、問題描述
設(shè)計并實現(xiàn)一個數(shù)制轉(zhuǎn)換器,能夠?qū)斎氲娜? -進制類型的數(shù)值轉(zhuǎn)換為指定的數(shù)制類型的數(shù)值。必須實現(xiàn)的數(shù)制類型有二進制、八進制、十進制和十六進制四種。
2、基本要求
(1)使用Spinner 控件,列出四種數(shù)制類型,即:二進制、八進制、十進制和十六進制;
(2)“數(shù)值”輸入框,不使用Android系統(tǒng)提供的輸入面板,進行數(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="進制轉(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="進制類型:" ? ? ? ? ? ? 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="進制類型:" ? ? ? ? ? ? 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="計算" ? ? ? ? ? ? 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)換為十進制; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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)換為十進制; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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)換為十進制; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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)換為十進制; ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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>二進制</item> ? ? ? ? <item>八進制</item> ? ? ? ? <item>十進制</item> ? ? ? ? <item>十六進制</item> ? ? </string-array> </resources>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android Studio 升級到3.0 提示 java.lang.NoClassDefFoundError的解決方法
這篇文章主要介紹了Android Studio 升級到3.0 提示 java.lang.NoClassDefFoundError的解決方法,需要的朋友可以參考下2017-12-12Android中使用Camera類編寫手機拍照App的實例教程
這篇文章主要介紹了Android中使用Camera類編寫手機拍照App的實例教程,整理了Camera調(diào)用硬件進行拍照的一些常用方法,需要的朋友可以參考下2016-04-04Android App中ListView仿QQ實現(xiàn)滑動刪除效果的要點解析
這篇文章主要介紹了Android App中ListView仿QQ實現(xiàn)滑動刪除效果的要點解析,重點是要判斷手勢按下的位置坐標,需要的朋友可以參考下2016-04-04進度條ProgressBar及ProgressDialog(實例)
下面小編就為大家?guī)硪黄M度條ProgressBar及ProgressDialog(實例)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07Android 自定義View時使用TypedArray配置樣式屬性詳細介紹
這篇文章主要介紹了Android 自定義View時使用TypedArray配置樣式屬性詳細介紹的相關(guān)資料,需要的朋友可以參考下2016-11-11