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.

Hashtable key value pair add put get pair Java Android example


AD MOB

How add pair of strings to Hashtable, how get pair key value from Hashtable, how split string, basic Java Android example.

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

397LW NO topic_id




AD

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


29

ListView add item click item basic Android example code | listview-add-item-click-item-basic-android-example-code


Definition of ListView in layout main.xml file Android example



<ListView android:id="@+id/idListView"
        android:background="#7700CC00"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" /> 



Code in Main.java ListView example source code Java Android

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ListView mlistView = (ListView) findViewById(R.id.idListView);
        mlistView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, 
                new String[] {"Game", "Help", "Home site"}));
    
        mlistView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
              // When clicked, show a toast with the TextView text Game, Help, Home
              Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                  Toast.LENGTH_SHORT).show();
            }
          });
     }
}


169

Iterate HashMap getKey getValue Java Example | iterate-hashmap-getkey-getvalue-java-example



 HashMap<String,Locale> _mapOfLocale = new HashMap<String,Locale>();
    _mapOfLocale.put("French",Locale.	FRENCH	);	
    _mapOfLocale.put("German",Locale.	GERMAN	);	
    _mapOfLocale.put("Italian",Locale.	ITALIAN	);	

    for (Entry<String, Locale> entry : _mapOfLocale.entrySet()) {

       System.out.println(entry.getKey());
       System.out.println(entry.getValue());

      }



2

Click Handler | click-handler-android-code


Click Handler Android Java example source code. Open new class as activity and open URL in browser.
In layout.xml file:



In string.xml

myClickHandler



In MainClass.java file

	public void myClickHandler(View view) {
		switch (view.getId()) {
		// open new class as activity
		case R.id.btnOpenClass: {
				Intent pictureActivity = new Intent(getBaseContext(),
						MyClass.class);
				startActivity(pictureActivity);
		}
		break;			
			
		case R.id.btnAbout: {
			//aboutDialogCreate();
		}
			break;
			
		// open url	
		 case R.id.btnHome: {
		 String url = "//android.okhelp.cz/";
		 Intent i = new Intent(Intent.ACTION_VIEW);
		 i.setData(Uri.parse(url));
		 startActivity(i);
		 }break;

		}

	}// end myClickHandler

// listener .. if click on button will scrolling to mTextView bottom
private OnClickListener mButtonListener = new OnClickListener() {
	    public void onClick(View v) {
	      // do something when the button is clicked
	    int nBottom =	mTextView.getBottom();
	    hScrollView.scrollTo(0, nBottom);
	    }
	};

295

Shuffle array int string Java Android | shuffle-array-int-string-java-android



String [] arOfStrings = {"one", "two", "three"};
List<String> mListOfStrings = new ArrayList<String>(Arrays.asList(arOfStrings));
Collections.shuffle(mListOfstrings);
String str = mListOfStrings.get(2);// 2 is index of pozition an element


int [] arOfInt = {1, 2, 3};
List<Integer> mListOfInt = new ArrayList<Integer>(Arrays.asList(arOfInt));
Collections.shuffle(mListOfInt);
167

INSTALL_FAILED_INSUFFICIENT_STORAGE | install_failed_insufficient_storage


1.) Try reopen the Emulaor and restart Eclipse.
OR
2.) Try to delete AVD from Eclipse menu Window - AVD manager.
OR
3.) Insert into manifest.xml this source code.

 <manifest xmlns:android="//schemas.android.com/apk/res/android"
    package="com.myweb.mypackage"
    android:installLocation="preferExternal"


Editace: 2013-12-09 10:56:37
Počet článků v kategorii: 397
Url:hashtable-key-value-pair-add-put-get-pair-java-android-example

AD
11 Share
Share
Tweet