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.

The Labeled continue statement Java example


AD MOB

The Labeled continue statement as goto Java example.


public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };
		OuterLoop: for (int e = 0; e < 4; e++) {
			for (int i = 0; i < arrayOfString.length; i++) {
				if (arrayOfString[i].equals("hello"))
					continue OuterLoop;
				System.out.println(arrayOfString[i]);
			}
		}
	}
}
/*
Hello
people
Hello
people
Hello
people
Hello
people
*/

397LW NO topic_id




AD

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


107

Memory usage of application in Android sample code | memory-usage-of-application-in-android-sample-code



public class MainClass extends Activity {
ActivityManager activityManager; 
MemoryInfo memoryInfo; 
final String TAG = "MemInfo";


@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
         memoryInfo = new ActivityManager.MemoryInfo();

        activityManager.getMemoryInfo(memoryInfo);
 
    	           Log.i(TAG, " memoryInfo.availMem " + memoryInfo.availMem);
    	           Log.i(TAG, " memoryInfo.lowMemory " + memoryInfo.lowMemory);
    	           Log.i(TAG, " memoryInfo.threshold " + memoryInfo.threshold);

  Toast.makeText(getApplicationContext(),  String.valueOf( memoryInfo.availMem), Toast.LENGTH_LONG)
		.show();

    } // end onCreate
}
164

Immutable bitmap passed to Canvas constructor - Android error | immutable-bitmap-passed-to-canvas-constructor-android-error


Try this source code:

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.my_image)
.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(myBitmap);
// etc.  ....... 


Issue: Immutable bitmap passed to Canvas constructor
Solution: Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.my_image)
.copy(Bitmap.Config.ARGB_8888, true);
71

For cycle loop in Java example | for-cycle-loop-in-java-example


Cycle for in Java example

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };

		for (int i = 0; // start position , first cycle i == 0
                      i < arrayOfString.length; // if i < 4 (length of array) do loop
                       i++ // incrementation after cycle
                       ){
			System.out.println(arrayOfString[i]); 
                       // i++ incrementation
		}
	}
}

171

WebView change height Android Example | webview-change-height-android-example


The Android WebView changing the height according to text size.
If you need to change the height to a minimum try this source:

//public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) 
WebView _webView; // findById(.....
String entryContent = "";
 _webView.loadDataWithBaseURL(
	"blabol",//  javascript i styly
	entryContent, null,
	"utf-8", null
);

345

Pixel to density independent pixel to pixel conversion | pixel-to-density-independent-pixel-to-pixel-conversion


Physical pixel (px)
Density independent pixel (dp)
Dots per inch (dpi) .. physical pixels per inch
px = dp * (dpi / 160)

public static int dpToPx(int dp)
{
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}

public static int pxToDp(int px)
{
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}


Editace: 2011-10-04 08:58:06
Počet článků v kategorii: 397
Url:the-labeled-continue-statement-java-example

AD
11 Share
Share
Tweet