Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

float in Java example code


AD MOB

Android development
Java float is 32 bit single precision type and used when fractional precision calculation is required.

Java float je 32 bitů veliké číslo sloužící především pro přesný výsledek za desetinnou tečkou například při dělení čísel. Pro větší přesnost použíijte 64 bitový typ Double.


		// declaration and assignment of value  type float
		float x = 18.41785f;
		//print formated  value
		System.out.printf("The value of x is %.3f%n", x); // 18.418
                
                // declaring more variables in single statement
                float f1 = 12.4F, f2 = 564.5F, f3 = 14.589F;

		// float range of value
		System.out.println(Float.MIN_VALUE); // 4E-45
		System.out.println(Float.MAX_VALUE); // 4028235E38

		// is NaN  Not-a-Number
		float f = (float) Math.sqrt(-15);
		boolean bNaN = Float.isNaN(f);
		System.out.print(bNaN); // true
		
                // check if a string is a valid number in Java example
                // convert string to float Java example
		String sF = "12.8";
		float fParse = Float.parseFloat(sF);

	       // convert strings to numbers
	      String sFl = "15.48";
	      float fFromString = (Float.valueOf(sFl)).floatValue();

// float to string in Java example code
Float fObj = new Float(68.5);
String str = fObj.toString();
// else 
Float fS = 11.6f;
String sFloat = fS.toString();

              // compare two float variables
	      Float fComp1 = 4.3f;
	      if(fComp1.equals(4.3f))
	  		System.out.print("true");

	    // compares the two specified float values in Java example
	    int i =	Float.compare(11.5f, 11.7f); // -1 first < second
	    // 0 first == second
	    // 1 first > second
	    System.out.print(i);



397LW NO topic_id




AD

Další témata ....(Topics)


305

How to set different locales in android | how-to-set-different-locales-in-android


- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder

// for locale English is default
/MyProject/res/values 
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">App English default</string>
    <string name="action_settings">Settings English default</string>
    <string name="hello_world">Hello world</string>

</resources>

// for locale Czech (cs)
/MyProject/res/values-cs
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Aplikace česky cs</string>
    <string name="action_settings">Nastavení česky</string>
    <string name="hello_world">Ahoj světe!</string>

</resources>

// for locale English US (r is region)
/MyProject/res/values-en-rUS

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">App English Us locale</string>
    <string name="action_settings">Settings English Us locale</string>
    <string name="hello_world">Hello world from USA :)</string>

</resources>


Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.
192

Samsung Galaxy Pocket - Android | samsung-galaxy-pocket-android


Nejmenší telefon od Samsungu s Androidem se někdy přidává i jako dárek k zakoupenému zboží, přesto tento telefon toho za svou cenu něco přes 2 000 korun umí hodně.
Technické parametry Samsung Galaxy Pocket
Rozměry a hmotnost: 103,70 × 57,50 × 12 mm, 97 g
Sítě GSM 850 / 900 / 1800 / 1900 MHz, W-CDMA (3G) 900 MHz / 2 100 MHz
Displej TFT TN, 2,80" (320 × 240 px), dotykový: kapacitní
Procesor 832 MHz
Paměť RAM 256 MB, vnitřní paměť 3 GB, paměťové karty microSD
Operační systém Android 2.3, údajně nelze upgradovat
Hudba: mp3, aac, wav, wma
Video: mp4, 3gp, 320 × 240 px, 15 FPS
Fotoaparát 2 Mpx
Navigace vestavěná GPS, elektronický kompas
Baterie 1 200 mAh, pohotovostní doba: 312 hodin
Cena něco přes 2 000 korun / léto 2012

samsung-galaxy-pocket
363

How rebuild only one module in project Android Studio | how-rebuild-only-one-module-in-project-android-studio


If you do click on Rebuid project menu item, this operation maybe consume long time on slovly PC.
Some errors dismis when you do rebuild project, or module.
Try this:
Select module where contains red error code and press Debugg or Run button on Android Studio.
If module code contains errors, Android Studio show error report in gradle console.
If not, apk will installed on device.
This is 10 times faster than Clean - Rebuild all project.
96

onSaveInstanceState() onRestoreInstanceState() basic Android example | onsaveinstancestate-onrestoreinstancestate-basic-android-example



public class MyClass extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       }
	 String sMyText = "some text";
	 int nMyInt = 10;

 @Override
 protected void onSaveInstanceState(Bundle outState) {
     // Save away the original text, so we still have it if the activity
     // needs to be killed while paused.
     outState.putString("my_text", sMyText);
     outState.putInt("my_int", nMyInt);
     Toast.makeText(this, "onSaveInstanceState()", Toast.LENGTH_LONG).show();
Log.i("onSaveInstanceState", "onSaveInstanceState()");
}
 String sNewMyText = "";
 int nNewMyInt = 0;
 
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
     super.onRestoreInstanceState(savedInstanceState);
     // restore saved values
     sNewMyText = savedInstanceState.getString("my_text");
     nNewMyInt = savedInstanceState.getInt("my_int");
     Toast.makeText(this, "onRestoreInstanceState()", Toast.LENGTH_LONG).show();
     Log.i("onRestoreInstanceState", "onRestoreInstanceState()");
     
 }
}
254

Spinner Text Size Android Example | spinner-text-size-android-example



      Spinner  _spin1 = (Spinner) findViewById(R.id.spinLangFirst);
      ArrayAdapter<String> adapterJazyky = new ArrayAdapter<String>(this,
              R.layout.spinner_text_layout.xml, {"one","two","etc...."});
      adapterJazyky.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      _spin1.setAdapter(adapterJazyky);





spinner_text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="//schemas.android.com/apk/res/android"
          android:id="@+id/spinnerText"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
         
         android:textSize="20sp"
/>


Editace: 2011-09-26 20:49:50
Počet článků v kategorii: 397
Url:float-in-java-example-code

AD
11 Share
Share
Tweet