Hashtable find value by key Java Android example
Hashtable find value by key Java Android basic example.
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 hashTable = new Hashtable();
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);
}
}
// check if key exists
if( hashTable.containsKey("two")){
System.out.print("two = " + hashTable.get("two"));
}
}
}
/*
two = zwei
*/
396LW NO topic_id
AD
Další témata ....(Topics)
Eclipse Error: The container JRE System Library JavaSE references non existing library QTJava.zip
Workaround:
Windows->Preferences->Java->Installed JRE
Press Add and select your JRE folder path for example:
c:\Program Files\Java\jre7\
and check your choice.
Workaround:
Windows->Preferences->Java->Installed JRE
Press Add and select your JRE folder path for example:
c:\Program Files\Java\jre7\
and check your choice.
You can get list by class Build
For example:
List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
For example:
if(Build.MANUFACTURER.equals("unknown")) {
// Emulator
}
List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
Brand | Motorola |
Model (codename) | Droid Razr |
Price (cena, včetně DPH v KCZ) | 10800 / 06.2012 |
Display size in Inch (v palcích) | 4.3 |
Display-resolution | 540x960 |
Dotek-typ | capacitive |
CPU typ | TI 4430 |
CPU MHz | 1.2 GB |
CPU core | 2 |
L2 cache | |
RAM | 1024 |
ROM | 15600 |
GPU | SGX540 |
NenaMark2 Benchmark | |
GPU-GLBenchmark | 3299 |
Baterie mAh | 1780 |
Foto MPx | 8 |
Autofocus | AF |
Video | HD video 30 frames/s |
Official Android ICS | Google Android 2.3.5 (Gingerbread) |
CyanogenMod support | |
Dotek-prstů-max | 10 |
Display-ppi | 256 |
Display-retina | 79% |
Networks | |
Connectivity | GSM: 850/900/1800/1900 MHz, EDGE, GPRS 3G: 900/2100 MHz, HSDPA, HSUPA, HSPA+ Bluetooth: 4.0 (EDR, A2DP, FTP, PBAP, AVRCP) Wi-Fi: 802.11b/g/n PC: microUSB, USB 2.0, microHDMI Senzors: proximity, gyroskop, akcelerometr GPS: yes, A-GPS, digital compas |
Note | Super AMOLED Display |
Motorola Droid Razr image
TypeFace, setTypeface, font, font family, array of String, Button create dynamically
@Override
protected void onStart() {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
48,
55
);
Typeface typeFace = Typeface.MONOSPACE;
String [] ar = {"A","B","C","D","E","F","G","H","J","K"};
for (int i = 0; i < ar.length; i++) {
Button buttonView = new Button(this);
buttonView.setText(Html.fromHtml("<b>"+ar[i]+"</b>"));
buttonView.setTextColor(Color.BLUE);
buttonView.setTextSize(27.f);
buttonView.setTypeface(typeFace,Typeface.BOLD);
buttonView.setOnClickListener(mThisButtonListener);
if(i%2==0)
mLayoutButtons.addView(buttonView, p);
else
mLayoutButtonsNextRow.addView(buttonView, p);
_listOfButtons.add(buttonView);
}
super.onStart();
}
//////// xml file
<TextView
android:id="@+id/text01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:fontFamily="Arial"
/>
Spinner, ArrayAdapter, setOnItemSelectedListener, onItemSelected, setDropDownViewResource
MainClass.java
strings.xml
MainClass.java
public class Vypocet extends Activity {
Spinner hSpinnerMetry;
// .......
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hSpinnerMetry = (Spinner) findViewById(R.id.idSpinnerMetry);
ArrayAdapter<CharSequence> adapterMetry = ArrayAdapter.createFromResource(
this, R.array.metry_array, android.R.layout.simple_spinner_item);
adapterMetry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
hSpinnerMetry.setAdapter(adapterMetry);
hSpinnerMetry.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> parent, View view, int position, long id) {
int nPos = position;
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
strings.xml
<string-array name="metry_array">
<item>m</item>
<item>dm</item>
<item>cm</item>
<item>mm</item>
</string-array>
Editace: 2013-12-09 10:56:31
Počet článků v kategorii: 396
Url:hashtable-find-value-by-key-java-android-example