toLowerCase Locale toUperCase Locale Java Android
String s = "AbcČ";
String s2 = s.toLowerCase(new Locale("cs_CZ")); // Czech Republic
String s3 = s.toLowerCase(new Locale("de_DE")); // Germany
//
en_US
en_GB
ar_EG
be_BY
bg_BG
ca_ES
cs_CZ
da_DK
de_DE
396LW NO topic_id
AD
Další témata ....(Topics)
Example from SDK C:\Program Files\Android\android-sdk-windows\samples\android-10\ApiDemos\src\com\example\android\apis\text\Link.java
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"
2.) Link text by setMovementMethod
3.) Link as html code using Html.fromHtml()
4.) Link string by SpannableString
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"
// res/values/strings.xml
<string name="link_text_auto"><b>text1:</b> This is some text. In
this text are some things that are actionable. For instance,
you can click on //www.google.com and it will launch the
web browser. You can click on google.com too. And, if you
click on (415) 555-1212 it should dial the phone.
</string>
// main.xml
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
<TextView xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/link_text_auto"
/>
2.) Link text by setMovementMethod
// MainActivity.java onCreate
/*Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable(boolean) again after calling this to get the focusability back the way you want it. */
TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
// main.xml
<!-- text2 uses a string resource containing explicit <a> tags to
specify links. -->
<TextView xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/link_text_manual"
/>
//strings.xml
<string name="link_text_manual"><b>text2:</b> This is some other
text, with a <a href="//www.google.com">link</a> specified
via an <a> tag. Use a "tel:" URL
to <a href="tel:4155551212">dial a phone number</a>.
</string>
3.) Link as html code using Html.fromHtml()
// MainActivity.java onCreate
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"<b>text3:</b> Text with a " +
"<a href="//www.google.com">link</a> " +
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
4.) Link string by SpannableString
SpannableString ss = new SpannableString(
"text4: Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView t4 = (TextView) findViewById(R.id.text4);
t4.setText(ss);
t4.setMovementMethod(LinkMovementMethod.getInstance());

Check
- is sett debug mode on device?
- enabled debugging over USB?
- is device right connected?
- have you downloaded and instaled drivers for your device on PC?
- For Windows //developer.android.com/sdk/win-usb.html
- try disconnect and connect USB cable
- try do restart Android Studio
Dil 4. ArticleFragment.java
V 1. dílu jsme se něco dozvěděli od XML souborech a typu procesoru pro správný běh Android Studia a emulátoru různých typů zařizení s Androidem.
V 2. dílu jsme rozebrali MainActivity.java
V 3. dílu jsme se zabývali HeadlinesFragment.java
V tomto dílu se podíváme na ArticleFragment.java soubor.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html Pozorně si jej nastudujte.
V 1. dílu jsme se něco dozvěděli od XML souborech a typu procesoru pro správný běh Android Studia a emulátoru různých typů zařizení s Androidem.
V 2. dílu jsme rozebrali MainActivity.java
V 3. dílu jsme se zabývali HeadlinesFragment.java
V tomto dílu se podíváme na ArticleFragment.java soubor.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html Pozorně si jej nastudujte.
package com.example.android.fragments;
// knihovna pro nižší verze Androidu
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
// extends Fragment - už nebude obsahovat funkci onCreate jako v Activity
// ale onCreateView
public class ArticleFragment extends Fragment {
// důležité pro uložení argumentu - argumentů (hodnot)
// pro obnovení předchozího stavu obsahu obrazovky
// např. při rotaci zařízení atd.
final static String ARG_POSITION = "position";
int mCurrentPosition = -1;
TextView article; // uložen do globální proměnné, v originale
// odchycen v updateArticleView() ale tam vracel NULL
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Když je activity znovu vytvořena (např. při rotaci zařízení),
// obnoví, v našem případě, text článku, jehož pozice
// byla uložena pomocí
// public void onSaveInstanceState(Bundle outState) viz níže
// důležité zejména pro dual-panel (dva panely vedle sebe)
if (savedInstanceState != null) {
mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
}
// umístíme, aktivujeme příslušný layout
// zde je zajímavé, že layout můžete měnit.
// Např. při kliknutí na pložku 1 v HeadlinesFragment
// zde můžete ochytit pozici a dle toho zvolit
// příslušný layout, který chcete zobrazit ve fragmentu
// ALE pak si musíte pohlídat ID prvků, které bude ten JINÝ
// layout obsahovat
// Oproti originalu odchytíme TextView již zde, v originalu to vyhazovalo chybu
View rootView = inflater.inflate(R.layout.vnitrek, container, false);
article = (TextView) rootView.findViewById(R.id.article);
return rootView;
}
@Override
public void onStart() {
super.onStart();
// Při startu fragmentu, zkontrolujte, zda existují nějaké argumenty
// předané do fragmentu.
// OnStart() je právě to správné místo, kde to udělat,
// protože layout s jednotlivými elementy byl již
// naloděn - aktivován, a můžeme bezpečně použít metody,
// které potřebují, aby jednotlivá ID elementů layoutu byla již
// aktivní, použitelná a nevracela NULL, což by mělo za následek
// pád aplikace
Bundle args = getArguments();
if (args != null) {
// vypsaní obsahu článku pomocí předaného argumentu (pozice) z HeadlinesFragment.java
updateArticleView(args.getInt(ARG_POSITION));
} else if (mCurrentPosition != -1) {
// vypsání článku dle pozice uložené např. při rotaci zařízení
// mCurrentPosition je definována (odchycena) v onCreateView
updateArticleView(mCurrentPosition);
}
}
/**
funkce která vypíše obsah článku do TextView.
Jako parametr int position je pozice položky,
na kterou bylo kliknuto v ListView v HeadlinesFragment.java
*/
public void updateArticleView(int position) {
// na rozdíl od Activity se ve Fragment používá k
// získání id ne jen findViewById()
// ALE getActivity().findViewById()
//Tento kod vracel article == NULL , PROTO bylo nutno odchytit TextView
// v onCreateView()
//TextView article = (TextView) getActivity().findViewById(R.id.article);
// vložení textu článku do TextView z Ipsum.java
// je to pole stringů, kde position je pozice stringu v poli
// static String[] Articles = {"","",""};
if (article != null)
article.setText(Ipsum.Articles[position]);
mCurrentPosition = position;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Uložení pozice článku - elementu, či jiných argumentů důležitých
// pro obnovení stavu v onCreateView() např. při rotaci zařízení
outState.putInt(ARG_POSITION, mCurrentPosition);
// TIP: zde můžeme vždy při rotaci zařízení podstrčit náhodnou pozici
// článku pomocí
// randomNum = minimum + (int)(Math.random() * maximum);
// a vytvořit tak zábavnou hru, například pro náhodné
// vypsání přísloví, či nějakého fyzikálního zákona atd.
// Stačí pak aby uživatel jen pootočil zařízení od 90° a zpět,
// k vypsání nové položky
}
}
GregorianCalendar cal = new GregorianCalendar(); Boolean b = cal.isLeapYear(2012); // true, Android example.
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
StringBuilder strBuild = new StringBuilder();
GregorianCalendar cal = new GregorianCalendar();
Boolean b = cal.isLeapYear(2012); // true
strBuild.append("Is leap year 2012? " + b + "
");
b = cal.isLeapYear(2014); // false
strBuild.append("Is leap year 2014? " + b + "
");
txtV.setText(strBuild);
}
}
SeekBar setOnSeekBarChangeListener Example. Change TextView font size by SeekBar Example.
TextView mTextView01 = (TextView)findViewById(R.id.textView01);
SeekBar mSeekBarTexSize = (SeekBar)findViewById(R.id.seekBarTextSize);
mSeekBarTexSize.setMax(100);
mSeekBarTexSize.setProgress(25);
mSeekBarTexSize.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mTextView01.setTextSize((float)progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
});
Editace: 2013-11-10 22:00:41
Počet článků v kategorii: 396
Url:tolowercase-locale-toupercase-locale-java-android