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.

Draw drawARGB() Android basic example


public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			//drawARGB (int a, int r, int g, int b)
//			a  alpha component (0..255) of the color to draw onto the canvas 
//			r  red component (0..255) 
//			g  green component (0..255)  
//			b  blue component (0..255)  

			canvas.drawARGB(255, 0, 255, 10); 
		}

	}
}



396LW NO topic_id




AD

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


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>




88

Map TreeMap key value pair sort by value Java Android example | map-treemap-key-value-pair-sort-by-value-java-android-example


Map TreeMap sorted by value Java Android example.

MainClass.java


import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

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

		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;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);
			}
		}
		for (Entry<String, String> entry: mapSortedByValues(map)) {
		    System.out.println(entry.getKey() + " = " + entry.getValue());
		}
	}

	static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> mapSortedByValues(
			Map<K, V> map) {
		SortedSet<Map.Entry<K, V>> sortedSetOfEntries = new TreeSet<Map.Entry<K, V>>(
				new Comparator<Map.Entry<K, V>>() {
					@Override
					public int compare(Map.Entry<K, V> entry_1, Map.Entry<K, V> entry_2) {
						int res = entry_1.getValue().compareTo(entry_2.getValue());
						return res != 0 ? res : 1; 
						// return entry_1.getValue().compareTo(entry_2.getValue());							
					}
				});
		sortedSetOfEntries.addAll(map.entrySet());
		return sortedSetOfEntries;
	}
}
/*
three = drei
one = eine
four = vier
two = zwei
 */

21

How to install mount SD card for Eclipse Android Emulator | how-install-sd-card-on-android-eclipse-emulator


If you want download some *.apk file from internet and try on your emulator you get error than you have to install SD card. You have to closing Android emulator.
Mount Android emulator SD card instruction

  1. In Eclipse go in menu Window - Android SDK and Avg Manager

  2. Select Virtual devices

  3. Select AVD Name where you need install SD card

  4. Click on Edit button

  5. In open dialog go to SD card - Size: and write 500

  6. Press button Edit AVD

  7. Run AVD emulator


Image how install SD card on Android emulator in Eclipse.