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.

Start Activity from ListView item click Android example

How start certain Activity if user clicked to ListView item
Start Activity from list – launches other activities from list - latest variant!!!!

public class Main extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        try {
			ListView mlistView = (ListView) findViewById(R.id.idListView);
			mlistView.setAdapter(new ArrayAdapter<String>(this,
			        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(),
              String sText = ((TextView) view).getText().toString();
              Intent intent = null;
              intent = new Intent(getBaseContext(),
              //else if(sText.equals("Help")) ..........

              if(intent != null)
        } catch (Exception e) {
        	// TODO Auto-generated catch block

Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml

        <activity android:name=".Game" android:label="GameLabel">

package cz.okhelp.listview;

import android.app.Activity;
import android.os.Bundle;

public class Game extends Activity{
    public void onCreate(Bundle savedInstanceState) {
        // you have to create game.xml 

397LW NO topic_id

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


Eclipse ADT plugin not recent graphical layout editor | eclipse-adt-plugin-not-recent-graphical-layout-editor

Click to Android version combobox - drop down menu and select your version, which just using (have instaled). For example: You updated ADT by SDK manager, but forget to update Android version. You can use lower version from drop down menu, which using your project, or do update of Android by SDK manager.

Eclipse revert old version Android Development Tools | eclipse-revert-old-version-android-development-tools

If you have trouble with compilation of new project after you make a update of android development tools you can go back to old version of the tools.

    • Open Help > About Eclipse... use the menu > About...

    • Click the "Installation Details" button.

    • Select the "Installation History" tab.

    • Select one of the previous configurations.

    • Click the "Revert" button at the bottom.




Android Emulator PC keyboard shortcuts | android-emulator-pc-keyboard-shortcuts

Basic shortcuts for Android Emulator.

Emulated Device Key Keyboard Key
Menu (left softkey) F2 or Page-up button
Star (right softkey) Shift-F2 or Page Down
Back ESC
Call/dial button F3
Hangup/end call button F4
Search F5
Power button F7
Audio volume up button KEYPAD_PLUS, Ctrl-5
Audio volume down button KEYPAD_MINUS, Ctrl-F6
Camera button Ctrl-KEYPAD_5, Ctrl-F3
Switch to previous layout orientation (for example, portrait, landscape) KEYPAD_7, Ctrl-F11
Switch to next layout orientation (for example, portrait, landscape) KEYPAD_9, Ctrl-F12
Toggle cell networking on/off F8
Toggle code profiling F9 (only with -trace startup option)
Toggle fullscreen mode Alt-Enter
Toggle trackball mode F6
Enter trackball mode temporarily (while key is pressed) Delete
DPad left/up/right/down KEYPAD_4/8/6/2
DPad center click KEYPAD_5
Onion alpha increase/decrease KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/)

More about Android Emulator

Shuffle List ArrayList Collections Java example | shuffle-list-arraylist-collections-java-example

Add and shuffle elements in LinkedList or ArrayList Java basic example.

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "End" };
		   List<String> arrayList = new LinkedList<String>();
            for(String s: arrayOfString)


[hello, world!, bye-bye, nothing, people, End, Hello]


Get Context Java Android example | get-context-java-android-example

getContext() getApplicationContext() method Java Android example source

Context myContext_1 = ThisClassName.this; // to open a Dialog
Context myContext_2 = getContext();
Context myContext_3 = this.getContext();
Context myContext_4 = this;
Context myContext_5 = this.getApplicationContext ();

OnClickListener getImageBtnOnClick = new OnClickListener() {
public void onClick(View view) {
Context context = view.getContext();

// Toast
Toast.makeText(getApplicationContext(), "Context == getApplicationContext "
, Toast.LENGTH_SHORT).show();

// store Context in public class
public class MyActivity extends Activity {
public static Context myCnt = null;
protected void onCreate(Bundle icicle) {
myCnt = this;
// or
// MyStorage.setContext(this);

// cntxFromStorage == this
Context cntxFromStorage = MyStorage.getContext();

public class MyStorage
private static Context cntStorageContext = null;

public static Context getContext() {
return cntStorageContext;

public static void setContext(Context context) {
MyStorage.cntStorageContext = context;


class DataBaseHelper extends SQLiteOpenHelper {
// get MyActivity context
Context cnt = MyStorage.getContext();


Editace: 2016-03-02 07:14:49
Počet článků v kategorii: 397