--- ------------------ --------------------- main.xml \u0026lt;? xml version = "1.0" encoding = "UTF-8"> \u0026lt;LinearLayout xmlns: android = " http://schemas.android.com/apk/res/android" ; android: orientation = "vertical" android \u0026lt;
EditText android : layout_width = "fill_parent" android: layout_height = "wrap_content" android: id = "@ + id/num1"
/> & # 160; \u0026lt;TextView android
: layout_width = "fill_parent" android: layout_height = "wrap_content" android: id = "@ + id / risultato"
& # 160; />
\u0026lt;Button android: id = "@ + id / Conv "
& # 160; android: layout_width = "fill_parent"
& # 160; android: layout_height = "wrap_content"
; android: text = "Converti in Binario"
; android: onClick = "conv"
/>
\u0026lt; Button android: id = "@ + id/Conv1"
& # 160; android: layout_width = "fill_parent"
& # 160; android: layout_height = "wrap_content"
; android: text = "Converti in decimal
; android: onClick = "toDec"
/>
\u0026lt;/ linear layout>
---------------------
Converti .
java ---------------------
org.me.binariotodecimale package;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
/**
* @author 4ALE */ public class Converti extends Activity {
    /** Called when the activity is first created. */
    @Override     public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
setContentView (R.layout.main)
;} public void
conv (View view) {
& # 160; numero1 = edit text (alt text) findViewById (R.id.num1)
int num1 = Integer . parseInt (numero1.getText (). toString ());
String bin = Integer.toBinaryString (num1);
TextView ris = (TextView) findViewById (R.id . risultato);
& # 160;} public void
toDec (View view) {
EditText number1 = (EditText) findViewById (R.id.num1)
        String num1=(numero1.getText().toString());
        int dec=Integer.parseInt(num1, 2);
        TextView ris=(TextView)findViewById(R.id.risultato);
        ris.setText("Decimale= "+dec);
}}
0 comments:
Post a Comment