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.

Map TreeMap get values to array Java Android example


import java.util.Map;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {

		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;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);
			}
		}
    Object[] objectArrayOfValues = map.values().toArray();
	for (int i = 0; i < objectArrayOfValues.length; i++) {
		System.out.println(objectArrayOfValues[i]);
	}
		 
		
	}// end main

}
/*
vier
eine
drei
zwei
zwei
 */

396LW NO topic_id




AD

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


367

Who has higher priority build.gradle or AndroidManifest Android Studio | who-has-higher-priority-build-gradle-or-androidmanifest-android-studio


build.gradle in module have higher priority then AndrodiManifest.xml
Try this.
AndroidManifest.xml have code:

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="23" />

build.gradle have code:

   defaultConfig {
        applicationId "cz.okhelp.words"
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 107
        versionName "1.0.7"
    }


Warning in AndroidManifest.xml:
This targetSdkVersion value (23) is not used; it is always overridden by the value specified in the Gradle build script (19) less... (Ctrl+F1)
The value of (for example) minSdkVersion is only used if it is not specified in the build.gradle build scripts. When specified in the Gradle build scripts, the manifest value is ignored and can be misleading, so should be removed to avoid ambiguity.
55

How update View TextView with timer Android runnable example | how-update-view-textview-with-timer-android-runnable-example


Update TextView by runnable. Handler, runnable, timer Android example.


public class TimerActivity extends Activity {
TextView hTextView;
Button hButton, hButtonStop;
private Handler mHandler = new Handler();
private int nCounter = 0;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        hTextView = (TextView)findViewById(R.id.idTextView);
        hButton = (Button)findViewById(R.id.idButton);
        hButton.setOnClickListener(mButtonStartListener);
        hButtonStop = (Button)findViewById(R.id.idButtonStop);
        hButtonStop.setOnClickListener(mButtonStopListener);
    } // end onCreate

View.OnClickListener mButtonStartListener = new OnClickListener() {
	public void onClick(View v) {
		try {
			mHandler.removeCallbacks(hMyTimeTask);
         //        Parameters
         //        r  The Runnable that will be executed. 
         //        delayMillis  The delay (in milliseconds) until the Runnable will be executed. 
                       mHandler.postDelayed(hMyTimeTask, 1000); // delay 1 second
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
};


private Runnable hMyTimeTask = new Runnable() {
	   public void run() {
		   nCounter++;
	    	   hTextView.setText("Hallo from thread counter: " + nCounter);
	   }
	}; 
/**
 * 
 */
    View.OnClickListener mButtonStopListener = new OnClickListener() {
    	public void onClick(View v) {
    		 mHandler.removeCallbacks(hMyTimeTask);
    		
    	}
    };
}





main.xml



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

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
	android:id="@+id/idTextView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button android:text="Button" 
android:id="@+id/idButton" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"></Button>
 
 <Button android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:id="@+id/idButtonStop" 
 android:text="Stop"></Button> 
    
    
</LinearLayout>




224

Eclipse custom skin GUI color theme | eclipse-custom-skin-gui-color


Eclipse make own color of toolbars, windows, status bar etc.
https://github.com/jeeeyul/eclipse-themes/wiki/Alternative-Install

android/eclipse-custom-skin-gui-2.jpg

android/eclipse-custom-skin-gui.png
91

Class File Editor - Source not found - Change Attached Source - Eclipse | class-file-editor-source-not-found-change-attached-source-eclipse


The source attachment does not contain the source for the file TextWatcher.class.
You can change the source attachment by clicking Change Attached Source below:

You have to add JDK src.zip path to dialog as on image below.
[caption id="attachment_1091" align="alignleft" width="282" caption="class file editor source not found Eclipse warning"]android/class-file-editor-source-not-found-282x300.png[/caption]



Or go to Project > Properties > Java Build Path > Libraries
Expand JRE System Library. Expand rt.jar.
Select Source attachment and double click or Edit.
Type path the source code file (External File…) and press OK.

[caption id="attachment_1094" align="alignleft" width="300" caption="Java project build path"]android/java-build-path-300x175.png[/caption]



Or type path in Java JRE definition



[caption id="attachment_1105" align="alignleft" width="300" caption="Java JRE deifiniton path in Eclipse"]android/java-jre-definition-eclipse-300x216.png[/caption]

How open String.class or others keywords definition with Eclipse.



Now if mouse move about keywords String or F3 on keywords and press button in yellow field will opened String.class
android/java-eclipse-tooltip-300x212.png




android/java-lang-string-class-300x210.png
269

How to Add Home Screen Widgets on Your Android Phone | how-to-add-home-screen-widgets-on-your-android-phone


Long press by finger on screen
From dialogue select Widgets
Select your widget
Put your widget on the screen

Video tutorial - to add home screen widgets - Android 2.1