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.

How set focus on View Android development example


AD MOB

Set focus on a View in Android application example source code for Button, EditText, View, TextView, isFocused(), requestFocus() .


// set focus on Button Android example
 private Button mRightButton;
 mRightButton = (Button) a.findViewById(R.id.rightButton);
 mRightButton.requestFocus();
// boolean isFocused() 
boolean b = mRightButton.isFocused(); // true or false

// set focus on TextView directly Android example
((TextView) findViewById(R.id.myText)).requestFocus();

// set focus on View Android example
private View mView;
mView = findViewById(R.id.showAll);
mView.requestFocus();

// set focus on EditText Android example
private EditText mEdit;
mEdit = (EditText)findViewById(R.id.myEdit);
mEdit.requestFocus();

397LW NO topic_id




AD

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


70

Foreach loop cycle in Java Android example | foreach-loop-cycle-in-java-android-example


Foreach in Java basic example source code.

MainClass.java


public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };

		for (String s : arrayOfString)
			System.out.println(s);

	}
}

394

CSS circle style html | css-circle-style-html



      create div with class with name e.g. circle

      create in styleSheet.css class circle



html code

 <div class="circle" id="">3</div>


css code

.circle {
 border-radius: 50%;
    width: 50px;
    height: 50px;
    background: yellow;
    position: absolute;
    display: block;
    border: 6px solid blue;
    font-size: 50px;
    text-align: center;
}






3




















12

TTS text to speech Android example | tts-text-to-speech


Android development example source code


// import
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
// you have to add implementation
public class Main extends Activity implements TextToSpeech.OnInitListener {
        private int _langTTSavailable = -1; // set up in onInit method
        // declaration
	private TextToSpeech mTts;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
// assigned handle - initialisation
			mTts = new TextToSpeech(this,
			        (OnInitListener) this  // TextToSpeech.OnInitListener
			        );
}

   // Implements TextToSpeech.OnInitListener.
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            // Set preferred language to US english.
             _langTTSavailable = mTts.setLanguage(Locale.US); // Locale.FRANCE etc.
            if (_langTTSavailable == TextToSpeech.LANG_MISSING_DATA ||
            	_langTTSavailable == TextToSpeech.LANG_NOT_SUPPORTED) {
             } else if ( _langTTSavailable >= 0) {
			 mTts.speak("Good morning",
            TextToSpeech.QUEUE_FLUSH,  // Drop all pending entries in the playback queue.
            null);
            }
        } else {
            // Initialization failed.
        }
    }

    @Override
    public void onDestroy() {
        // TTS shutdown!
        if (mTts != null) {
            mTts.stop();
            mTts.shutdown();
        }

        super.onDestroy();
    }

}










Get supported language:


private TextToSpeech mTts;
// public void onInit(int status){
int result;
String s;
result = mTts.setLanguage(	Locale.	CANADA	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CANADA	 not supported<br>"	;}else{s+="	CANADA	 supported<br>";}
result = mTts.setLanguage(	Locale.	CANADA_FRENCH	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CANADA_FRENCH	 not supported<br>"	;}else{s+="	CANADA_FRENCH	 supported<br>";}
result = mTts.setLanguage(	Locale.	CHINA	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CHINA	 not supported<br>"	;}else{s+="	CHINA	 supported<br>";}
result = mTts.setLanguage(	Locale.	CHINESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CHINESE	 not supported<br>"	;}else{s+="	CHINESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	ENGLISH	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ENGLISH	 not supported<br>"	;}else{s+="	ENGLISH	 supported<br>";}
result = mTts.setLanguage(	Locale.	FRANCE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	FRANCE	 not supported<br>"	;}else{s+="	FRANCE	 supported<br>";}
result = mTts.setLanguage(	Locale.	FRENCH	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	FRENCH	 not supported<br>"	;}else{s+="	FRENCH	 supported<br>";}
result = mTts.setLanguage(	Locale.	GERMAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	GERMAN	 not supported<br>"	;}else{s+="	GERMAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	GERMANY	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	GERMANY	 not supported<br>"	;}else{s+="	GERMANY	 supported<br>";}
result = mTts.setLanguage(	Locale.	ITALIAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ITALIAN	 not supported<br>"	;}else{s+="	ITALIAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	ITALY	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ITALY	 not supported<br>"	;}else{s+="	ITALY	 supported<br>";}
result = mTts.setLanguage(	Locale.	JAPAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	JAPAN	 not supported<br>"	;}else{s+="	JAPAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	JAPANESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	JAPANESE	 not supported<br>"	;}else{s+="	JAPANESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	KOREA	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	KOREA	 not supported<br>"	;}else{s+="	KOREA	 supported<br>";}
result = mTts.setLanguage(	Locale.	KOREAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	KOREAN	 not supported<br>"	;}else{s+="	KOREAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	PRC	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	PRC	 not supported<br>"	;}else{s+="	PRC	 supported<br>";}
result = mTts.setLanguage(	Locale.	ROOT	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ROOT	 not supported<br>"	;}else{s+="	ROOT	 supported<br>";}
result = mTts.setLanguage(	Locale.	SIMPLIFIED_CHINESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	SIMPLIFIED_CHINESE	 not supported<br>"	;}else{s+="	SIMPLIFIED_CHINESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	TAIWAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	TAIWAN	 not supported<br>"	;}else{s+="	TAIWAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	TRADITIONAL_CHINESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	TRADITIONAL_CHINESE	 not supported<br>"	;}else{s+="	TRADITIONAL_CHINESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	UK	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	UK	 not supported<br>"	;}else{s+="	UK	 supported<br>";}
result = mTts.setLanguage(	Locale.	US	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	US	 not supported<br>"	;}else{s+="	US	 supported<br>";}

305

How to set different locales in android | how-to-set-different-locales-in-android


- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder

// for locale English is default
/MyProject/res/values 
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">App English default</string>
    <string name="action_settings">Settings English default</string>
    <string name="hello_world">Hello world</string>

</resources>

// for locale Czech (cs)
/MyProject/res/values-cs
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Aplikace česky cs</string>
    <string name="action_settings">Nastavení česky</string>
    <string name="hello_world">Ahoj světe!</string>

</resources>

// for locale English US (r is region)
/MyProject/res/values-en-rUS

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">App English Us locale</string>
    <string name="action_settings">Settings English Us locale</string>
    <string name="hello_world">Hello world from USA :)</string>

</resources>


Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.
380

Android Studio Browse Files Data Device Emulator | android-studio-browse-data-device-emulator


1.) Open DDMS via Menu Tools > Android > Android Device Monitor
2.) Select Device
3.) In DDMS click Menu Window > Show View > File Exlporer
4.) Device > Storage folder
5.) Emulator > data > data folder


Editace: 2011-10-09 13:08:13
Počet článků v kategorii: 397
Url:how-set-focus-on-view-android-development-example

AD
11 Share
Share
Tweet