Create TextView dynamically Android sample
Example source code for Android Developers
// clickable TextView
public TextView createTextView(String sText, Context con){
TextView b = null;
try {
b = new TextView (con);
b.setTextSize(15.0f);
b.setTextColor(Color.rgb( 0, 0, 200));
b.setOnClickListener(this);
b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
b.setText(sText);
//tr.addView(b, 60,30);
} catch (Exception e) {
e.printStackTrace();
return b;
}
return b;
}
/*****************/
public void onClick(View view) {
try {
String s = ((TextView) view).getText().toString();
}
catch (Exception e1) {
e1.printStackTrace();
}
}
/***********/
// if you want restore in TextView after chagne of orientation
// you have to put code to Manifest.xml android:configChanges
activity android:name=".main"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" //this line important !!!!!!!
396LW NO topic_id
AD
Další témata ....(Topics)
Fill the entire canvas with the specified color.
@Override
public void onDraw(Canvas canvas) {
canvas.drawColor(Color.GREEN);
}
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) {}
});
build.gradle in module have higher priority then AndrodiManifest.xml
Try this.
AndroidManifest.xml have code:
build.gradle have code:
Warning in AndroidManifest.xml:
Try this.
AndroidManifest.xml have code:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="23" />
build.gradle have code:
defaultConfig {
applicationId "cz.okhelp.words"
minSdkVersion 9
targetSdkVersion 19
versionCode 107
versionName "1.0.7"
}
Warning in AndroidManifest.xml:
This targetSdkVersion value (23) is not used; it is always overridden by the value specified in the Gradle build script (19) less... (Ctrl+F1)
The value of (for example) minSdkVersion is only used if it is not specified in the build.gradle build scripts. When specified in the Gradle build scripts, the manifest value is ignored and can be misleading, so should be removed to avoid ambiguity.
If you change the package name, you have to add new package name in:
DictionaryProvider.java
Do not forget change package name in all java class and xml/searchable.xml
In my project I changed like this:
DictionaryProvider.java
public class DictionaryProvider extends ContentProvider {
String TAG = "DictionaryProvider";
// public static String AUTHORITY = "com.example.android.searchabledict.DictionaryProvider";
// change to your new package name
public static String AUTHORITY = "com.myweb.mysubdomen.searchabledict.DictionaryProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/dictionary");
// in AndroidManifest.xml
//change com.example.android to your package e.g. com.myweb.mysubdomen
<!-- Provides search suggestions for words and their definitions. -->
<provider android:name="com.example.android.searchabledict.DictionaryProvider"
android:configChanges="keyboard|keyboardHidden|orientation"
android:authorities="com.example.android.searchabledict.DictionaryProvider" />
<!-- Points to searchable activity so the whole app can invoke search. -->
<meta-data android:name="android.app.default_searchable"
android:configChanges="keyboard|keyboardHidden|orientation"
android:value=".SearchableDictionary" />
// I change like this:
<!-- Provides search suggestions for words and their definitions. -->
<provider android:name=".DictionaryProvider"
android:configChanges="keyboard|keyboardHidden|orientation"
android:authorities="cz.okhelp.android.searchabledict.DictionaryProvider" />
<!-- Points to searchable activity so the whole app can invoke search. -->
<meta-data android:name="android.app.default_searchable"
android:configChanges="keyboard|keyboardHidden|orientation"
android:value=".SearchableDictionary" />
Do not forget change package name in all java class and xml/searchable.xml
In my project I changed like this:
<searchable xmlns:android="//schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:hint="@string/search_hint"
android:searchSettingsDescription="@string/settings_description"
android:searchSuggestAuthority="cz.okhelp.android.searchabledict.DictionaryProvider"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestIntentData="content://cz.okhelp.android.searchabledict.DictionaryProvider/dictionary"
android:searchSuggestSelection=" ?"
android:searchSuggestThreshold="1"
android:includeInGlobalSearch="true"
>
</searchable>
Android development
long is 64 bit signed type and used when int is not large enough to hold the value.
long je celé číslo 64 bitů -9223372036854775808 +9223372036854775807 a používá se tam, kde typ int není schopen pojmout takovou hodnotu čísla.
long is 64 bit signed type and used when int is not large enough to hold the value.
long je celé číslo 64 bitů -9223372036854775808 +9223372036854775807 a používá se tam, kde typ int není schopen pojmout takovou hodnotu čísla.
// declaration and assignment of value type long
long n = 22337203685477580L;
// print formated value
System.out.printf("The value of x is %d%n", n); // 22337203685477580
System.out.format("%+,8d%n%n", n); // +22 337 203 685 477 580
// declaring more variables in single statement
long lo1 = 12L, lo2 = 56, lo3 = 1455555555589L;
// long range of value
System.out.println(Long.MAX_VALUE); // 9223372036854775807
System.out.println(Long.MIN_VALUE); // -9223372036854775808
// check if a string is a valid number in Java example
// convert string to long Java example
String sLong = "1288888888888888";
long longParse = Long.parseLong(sLong);
// convert strings to numbers
long longFromString = (Long.valueOf(sLong)).longValue();
// long to string in Java example code
Long longObj = new Long(229999999999L);
String str = longObj.toString();
// else
Long longS = 888888888888L;
String strLong = longS.toString();
// compare two long variables
Long longComp1 = 5555L;
if (longComp1.equals(55555555L))
System.out.print("true");
// compares the two specified long values in Java example
int i = longS.compareTo(444444L); // -1 first < second
// 0 first == second
// 1 first > second
System.out.print(i);
Editace: 2011-10-22 07:28:43
Počet článků v kategorii: 396
Url:create-textview-dinamically