Hashtable key value pair add put get pair Java Android example
How add pair of strings to Hashtable, how get pair key value from Hashtable, how split string, basic Java Android example.
MainClass.java
MainClass.java
import java.util.Enumeration;
import java.util.Hashtable;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };
Hashtable<String, String> hashTable = new Hashtable<String, String>();
for(String s: arrayOfString){
String[] array = s.split(";");
String sKey ="", sValue="";
if(array.length > 1){
sKey = array[0]; sValue = array[1];
hashTable.put(sKey, sValue);
}
}
Enumeration<String> enumer = hashTable.keys();
while (enumer.hasMoreElements()) {
String keyFromTable = (String) enumer.nextElement();
// get Returns the value to which the specified key is mapped,
// or null if this map contains no mapping for the key
System.out.println(keyFromTable + " = " + hashTable.get(keyFromTable));
}
}
}
/*
two = zwei
one = eine
three = drei
*/
396LW NO topic_id
AD
Další témata ....(Topics)
// on bottom of onCreate add listener
mInterstitialAd .setAdListener(new AdListener(){
public void onAdLoaded(){
interstitial.show();
}
});
} // end onCreate
public void displayInterstitial (){
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Error parsing the sdk.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Failed to create C:\Program Files\android\sdk\add-ons.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Unable to parse SDK content.
You have to create add-ons folder as admin of PC
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Failed to create C:\Program Files\android\sdk\add-ons.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Unable to parse SDK content.
You have to create add-ons folder as admin of PC
Eclipse: failed to create the java virtual machine - message box
- Open folder with Eclipse.exe and find eclipse.ini file
- Replace -vmargs
by your current real path of javaw.exe:
-vm "c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe"
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120522-1813
-product
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256M
-showsplash
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vm "c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe”
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx768m
-Declipse.buildId=v21.1.0-569685
String s = "Some text for appending
";
TextView mTitle = (TextView) findViewById(R.id.title_text);
mTitle.setText(R.string.app_name); // insert text from strings.xml
mTitle.append(s); // append string like a variable value
mTitle.append("My string will appended
"); // append string
You can insert this source code into onCreate in your activity file
Constructor SimpleCursorAdapter is deprecated.
If using api 11 and above, you can try add last parameter 0.
If using api 11 and above, you can try add last parameter 0.
Cursor cursor = managedQuery(...........,,,,);
// Specify the columns we want to display in the result
String[] from = new String[] { KEY_WORD,
KEY_DEFINITION };
// Specify the corresponding layout elements where we want the columns to go
int[] to = new int[] { R.id.word,
R.id.definition };
// deprecated
SimpleCursorAdapter words =
new SimpleCursorAdapter(this,
R.layout.result, cursor, from, to);
// working
SimpleCursorAdapter words =
new SimpleCursorAdapter(this,
R.layout.result, cursor, from, to, 0); // to, 0!!!!
//working in Fragment
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_2, null,
new String[] { "name", "age" }, // cursor parameters
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
Editace: 2013-12-09 10:56:37
Počet článků v kategorii: 396
Url:hashtable-key-value-pair-add-put-get-pair-java-android-example