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.

Not request focus EditText if startup Android

Not request focus EditText if startup Android - hide keyboard if startup.

Remove: from EditText

Create a LinearLayout and set the:
attributes android:focusable="true" android:focusableInTouchMode="true"

        android:orientation="vertical" >

397LW NO topic_id

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


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
<?xml version="1.0" encoding="utf-8"?>

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


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

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


// for locale English US (r is region)

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

    <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>


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.

Delete Bitmap Android Example | delete-bitmap-android-example

If some memory leak - problem try release of memory used of a big Bitmap what already not to need;
Bitmpap bmp; // not null
bmp = null;

final boolean bmpIsRecycled = bmp.isRecycled()
// Returns true if this bitmap has been recycled.

Free the native object associated with this bitmap, and clear the reference to the pixel data. This will not free the pixel data synchronously; it simply allows it to be garbage collected if there are no other references. The bitmap is marked as "dead”, meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing. This operation cannot be reversed, so it should only be called if you are sure there are no further uses for the bitmap. This is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this bitmap.

Download file from URL | download-file-from-url

Download image file from URL to ImageView Java Android source example code.

Context context = thisClass.this;
Drawable image = ImageOperations(context,
ImageView imgView;
imgView = (ImageView)findViewById(R.id.idImageView);

	private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
		try {
			InputStream is = (InputStream) this.fetch(url);
			Drawable d = Drawable.createFromStream(is, "src");
			return d;
		} catch (MalformedURLException e) {
			return null;
		} catch (IOException e) {
			return null;

	public Object fetch(String address) throws MalformedURLException,IOException {
		URL url = new URL(address);
		Object content = url.getContent();
		return content;

How to test dual panels - panes fragments on small device screen Android | how-to-test-dual-panels-fragments-on-small-device-screen-android

If You have old PC (Android in emulator with high screen resolution uses a lot of memory) or your testing phone have small screen, You can try this trick.
Rename layout folder for small device screen f.g. from layout into layout-swXXXdp and a large layout-sw600dp into layout.
Your phone with small screnn will do select xml file from renamed layout folder (for small screen).
You can to testing rotation with device en stability of fragments if an application changed orientation.
If you have old pc, you can try to make a new virtual device running on older version of Android, which uses less memory of computer.
For testing of rotation stability - application orientation changed - use on emulator Ctrl+F11, Ctrl+F12 key (Windows).

Before the release of application, you have to rename layout folder to older name layout-sw600dp and layout-swXXXdp to layout.

Map TreeMap key value pair sort by key, using of iterator Java Android example | map-treemap-key-value-pair-sort-by-key-using-of-iterator-java-android-example

Map TreeMap key value pair, Map sort by key, Iterator for Map Java Android example.


import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {
		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "three;drei", "four;vier" };

		Map<String, String> map = new TreeMap<String, String>();
		for(String s: arrayOfString){
	    	String[] array = s.split(";");
	    	String sKey ="", sValue="";
	    	if(array.length > 1){
	    	sKey = array[0]; sValue = array[1];
	    		map.put(sKey, sValue);
		List sortedByKeys=new ArrayList(map.keySet());
            // iterate map
	    Set references = map.keySet();
	    Iterator it = references.iterator();
	    while (it.hasNext()) {
	      String key = (String) it.next();
	      String value = map.get(key);
	      System.out.println(key + " = " + value);
            // or other example how iterate map
	    TreeSet<String> keys = new TreeSet<String>(map.keySet());
	    for (String key : keys) { 
	       String value = map.get(key);
	       System.out.println(key + " = " + value);

       // check if key exists 	    
//	   if( map.containsKey("two")){
//		System.out.print("two = " + map.get("two"));
//	   }
four = vier
one = eine
three = drei
two = zwei

Editace Jana Žákovská : 2013-02-01 16:57:04
Počet článků v kategorii: 397