double in Java example for Android development
Java double is 64 bit double precision type used when fractional
precision calculation is required.
Java double je datový typ (reálné číslo) o velikosti 64 bitů. Používá se například pro přesný výsledek po dělení za desetinnou tečkou. Pokud nepotřebuje tak veliké číslo použijte raději typ float, šetříte tím paměť mobilního telefonu.
precision calculation is required.
Java double je datový typ (reálné číslo) o velikosti 64 bitů. Používá se například pro přesný výsledek po dělení za desetinnou tečkou. Pokud nepotřebuje tak veliké číslo použijte raději typ float, šetříte tím paměť mobilního telefonu.
// declaration and assignment of value type double
double x = 18.41785;
//print formated value
System.out.printf("The value of x is %.3f%n", x); // 18.418
// declaring more variables in single statement
double d1 = 12.4, d2 = 564.5, d3 = 14.589;
// double range of value
System.out.println(Double.MIN_VALUE); // 4.9E-324
System.out.println(Double.MAX_VALUE); // 1.7976931348623157E308
// is NaN Not-a-Number
double f = (double) Math.sqrt(-15);
boolean bNaN = Double.isNaN(f);
System.out.print(bNaN); // true
// check if a string is a valid number in Java example
// convert string to double Java example
String sD = "12.8";
double dParse = Double.parseDouble(sD);
// convert strings to numbers
String sDl = "15.48";
double dFromString = (Double.valueOf(sDl)).doubleValue();
// format double, float or long value to string
DecimalFormat formatter = new DecimalFormat(".##");
String s = formatter.format(-.5678); // -0.57
// .### -0.568
// .#### -0.5678
// .000000 -.567800
// -123.456
// .## -123.46
// #.## -123.46
// #E0 -.1E3
// ##E0 -1.2E2
//###E0 -123E0
// double to string in Java example code
Double dObj = new Double(68.5);
String str = dObj.toString();
// else
Double dS = 11.6;
String sdouble = dS.toString();
// compare two double variables
Double dComp1 = 4.3;
if(dComp1.equals(4.3))
System.out.print("true");
// compares the two specified double values in Java example
// int i = compare(double d1, double d2);
int i = Double.compare(11.5, 11.7); // -1 first < second
// 0 first == second
// 1 first > second
System.out.print(i);
396LW NO topic_id
AD
Další témata ....(Topics)
/data/data/<package>/shared_prefs/<package>_preferences.xml
String TAG = "MyActivityName";
File f = new File("/data/data/"+this.getPackageName()
+"/shared_prefs/"+this.getPackageName()+"_preferences.xml");
if(f.exists())
Log.d(TAG, "exist");
else
Log.d(TAG, "not exist");
Set, get string , array of array of strings, Java example code
public final static String[][]_arArOfString_1 = {
new String[] {"bla","bla","hello world!"},
new String[] {},
new String[] {},
new String[] {},
new String[] {},
new String[] {}
};
String sOut = _arArOfString_1[0][2]; // hello world!
Set in AndroidManifest.xml android:theme="@android:style/Theme.NoTitleBar" AndroidManifest.xml example source code.
AndroidManifest.xml
AndroidManifest.xml
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="com.myexample.without_titlebar">
<application android:label="My app">
<activity android:name="NoTitleBar"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
drawPath, canvas.rotate, lineTo basic Android example for your testing.
|
|
|
|
// //www.apache.org/licenses/LICENSE-2.0
// The Android Open Source Project
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
private Paint mPaint = new Paint();
private Path mPath = new Path();
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
// Construct a wedge-shaped path
mPath.moveTo(0, -60);
mPath.lineTo(-20, 80);
mPath.lineTo(0, 60);
mPath.lineTo(20, 80);
mPath.close();
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = mPaint;
canvas.drawColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.flower_blue);
canvas.drawBitmap(bitmapOrg, 10, 10, paint);
int w = canvas.getWidth();
int h = canvas.getHeight();
int cx = w / 2;
int cy = h / 2;
canvas.translate(cx, cy);
// uncomment next line
//canvas.rotate(90.0f);
canvas.drawPath(mPath, mPaint);
}
}
}
TableRow TableLayout table row add delete remove removeview addview get table row index indexOfChild create table row dynamically TextView dynamically Android example
Main.java
main.xml ScrollView, TableLayout, TableRow, TextView Android xml layout example
Main.java
TableLayout table = (TableLayout)findViewById(R.id.table);
TableRow row = (TableRow)findViewById(R.id.row);
// get table row index android.
int nIndex = table.indexOfChild(row);
table.removeView(row); // invisible and height == 0
// add row into same place
table.addView(row, nIndex); // visible
// add row into certain position
table.addView(row, 3); // visible
// create new TableRow dynamically
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// create own function for append TableRow
private void appendRow(TableLayout table) {
TableRow row = new TableRow(this);
TextView hLabel = new TextView(this);
hLabel.setText("Some text");
hLabel.setPadding(3, 3, 3, 3);
TextView hNextLabel = new TextView(this);
hNextLabel.setText("Next text");
hNextLabel.setPadding(3, 3, 3, 3);
hNextLabel.setGravity(Gravity.RIGHT | Gravity.TOP);
row.addView(hLabel, new TableRow.LayoutParams(1));
row.addView(hNextLabel, new TableRow.LayoutParams());
table.addView(row, new TableLayout.LayoutParams());
}
main.xml ScrollView, TableLayout, TableRow, TextView Android xml layout example
<ScrollView xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row index 0"/>
</TableRow>
<TableRow android:id="@+id/row">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row index 1"/>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row index 2"/>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row index 3"/>
</TableRow>
</TableLayout>
</ScrollView>
Editace: 2011-09-26 20:49:42
Počet článků v kategorii: 396
Url:double-in-java-example-for-android-development