Tag Archives: example

17,056 views

Create About Dialog Android Example

Wiktionary – SDK samples Android protected void showAbout() { // Inflate the about message contents View messageView = getLayoutInflater().inflate(R.layout.about, null, false);   // When linking text, force to always use default color. This works // around a pressed color state … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on Create About Dialog Android Example
4,442 views

Include xml into another xml Android Example

How include layout defined in other xml file into another xml file example: res/layout/my_layout.xml into main.xml <include layout="@layout/my_layout" android:id="@+id/idMyLayout" />

Posted in Android Examples Code | Tagged , | Comments Off on Include xml into another xml Android Example
13,564 views

Cross Button in EditText Android

Cross Button in EditText Android for deleting clearing text in EditText Example source code: Example allow delete text in EditText by cross button, or do Button click performance. main.xml type your package name and class Put into drawable folder cross … Continue reading

Posted in Android Examples Code, Bitmap, drawing | Tagged , | Comments Off on Cross Button in EditText Android
35,881 views

SparseArray instead HashMap Android example

Old code with HashMap Map<Integer, Bitmap> _bitmapCache = new HashMap<Integer, Bitmap>(); private void fillBitmapCache() { _bitmapCache.put(R.drawable.icon, BitmapFactory.decodeResource(getResources(), R.drawable.icon)); _bitmapCache.put(R.drawable.abstrakt, BitmapFactory.decodeResource(getResources(), R.drawable.abstrakt)); _bitmapCache.put(R.drawable.wallpaper, BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper)); _bitmapCache.put(R.drawable.scissors, BitmapFactory.decodeResource(getResources(), }   Bitmap bm = _bitmapCache.get(R.drawable.icon); Lint warning: Use new SparseArray(…) instead for better … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , | Comments Off on SparseArray instead HashMap Android example
3,793 views

How to save the state of Activity – Android

onSaveInstanceState, onRestoreInstanceState , save preferences int mCurrentPhotoIndex = 0; @Override protected void onSaveInstanceState(Bundle outState) { outState.putInt("photo_index", mCurrentPhotoIndex); super.onSaveInstanceState(outState); }   @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { mCurrentPhotoIndex = savedInstanceState.getInt("photo_index"); super.onRestoreInstanceState(savedInstanceState); }   // or save preferences for new start of … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on How to save the state of Activity – Android
2,636 views

Throwing multiple exceptions Java

Throws multiple exceptions Java example source code public void callFc() throws IndexOutOfBoundsException, ArithmeticException { // my code for example: String[] sArray = {"aa","bb"}; String str = sArray[5]; // IndexOutOfBoundsException   int n = 5 / 0; // ArithmeticException }   … Continue reading

Posted in Android Examples Code, Bugs, warnings, errors | Tagged , | Comments Off on Throwing multiple exceptions Java
4,397 views

Java pass variable as reference

Integer, Float, String, List passed as reference in JAVA example source code: // List passed as reference JAVA List<Integer>list = new ArrayList<Integer>();   public void fc (List<Integer>listRef){ listRef.add(7); listRef.add(5); } fc(list); // 7, 5     // String passed as … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on Java pass variable as reference
13,329 views

How to programmatically set the button style – Android

How set rounded corners and own styles ActivityMy.java Button btn.setBackgroundResource(R.drawable.back_button_answer); \res\drawable\back_button_answer.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="10dip" /> <!– background –>   <gradient android:startColor="#D6D7D6" android:centerColor="#E2E2E2" android:centerY="0.75" android:endColor="#D6D7D6" android:angle="270" />   <stroke android:width="2dip" android:color="#fff"/> </shape>

Posted in Android Examples Code | Tagged , | Comments Off on How to programmatically set the button style – Android
2,993 views

LinkedMap HashMap Java

Map<Float,String> linkedHashMap = new LinkedHashMap<Float, String>();   linkedHashMap.put(14.f, "text"); linkedHashMap.put(13.f, "text"); linkedHashMap.put(10.f, "text"); linkedHashMap.put(11.f, "text"); linkedHashMap.put(2.f, "text"); linkedHashMap.put(3.f, "text"); linkedHashMap.put(1.f, "text"); linkedHashMap.put(7.f, "text"); linkedHashMap.put(23.f, "text");   for (Entry<Float,String> entry : linkedHashMap.entrySet()) { System.out.println(entry.getKey()); } 14.0 13.0 10.0 11.0 2.0 3.0 … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged | Comments Off on LinkedMap HashMap Java
10,150 views

java.lang.NullPointerException: println needs a message

Problemi is in e.getMessage() what can return null and Log.e (String tag, String msg) will throws an new exception !!!! Problem and solution: try { int [] i = {1}; int z = i[5]; } catch (ArrayIndexOutOfBoundsException e) { String … Continue reading

Posted in Android Examples Code, Bugs, warnings, errors | Tagged , | Comments Off on java.lang.NullPointerException: println needs a message