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.

Create array of strings in xml file Android example


Example source code for Android developers how create array of strings in *.xml file.
You can using array of strings in Spinner ( combobox - dropdown list ) or ListView etc.

    <string-array name="colors">

397LW NO topic_id


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


Include xml into another xml Android Example | include-xml-into-another-xml-android-example

How include layout defined in other xml file into another xml file example:
res/layout/my_layout.xml into

<include  layout="@layout/my_layout" android:id="@+id/idMyLayout" />

Sqlite create database and table with BAT file for Android | sqlite-create-database-and-table-with-bat-file

Sqlite3 create database and table with load.bat file and fill data to table example.

  1. Create folder for your project: my_sqlite_project

  2. Open folder and create file load.bat and paste to load.bat this text and save to project folder:

    sqlite3 my_database.s3db < load_text.sql

  3. Create load_text.sql file and paste this text and save to project folder:

    CREATE TABLE [android_metadata] (
    [locale] TEXT

    CREATE TABLE [my_table] (
    [_id] int NULL,
    [word] VARCHAR(255) NULL,
    [description] VARCHAR(255) NULL

    .separator ";"
    .import text_file.txt my_table

  4. Create text_file.txt and paste this text and save it as UTF-8:

    1;word1;my first word
    2;word2; my second word

  5. Download sqlite3.exe and put to project folder.

  6. Run BAT file load.bat and read text instruction from console

  7. If database created you can open and edit this with sqlite database explorer

  8. Copy database to Asses Android project folder

  9. If you want using this database in Android application on device, you have to copy this database to folder on device /data/data/com.MyPackage/databases/


Read file from URL | read-file-from-url

Read file from URL to array of byte and convert to UTF-8 String Android examle source code.

URL urlLoc = new URL("//myweb.com/myfile.html");
URLConnection conexion = urlLoc.openConnection();

// downlod the file
InputStream input = new BufferedInputStream(urlLoc

StringBuffer responseBuffer = new StringBuffer();
byte[] byteArray = new byte[1024];
while (input.read(byteArray) != -1)
        String res = new String(byteArray, "UTF-8");
        byteArray = null;
        byteArray = new byte[1024];

String response = responseBuffer.toString().trim();


Android Studio formatting code Ctrl + Alt + L | android-studio-formatting-code-ctrl-alt-l

Ctrl + Alt + L (format selection or all page)
Ctrl + Alt + Shift + L (show a dialog)
Ctrl + Windows Key + Alt + L

From menu Code
Code > Reformat Code

Who has higher priority build.gradle or AndroidManifest Android Studio | who-has-higher-priority-build-gradle-or-androidmanifest-android-studio

build.gradle in module have higher priority then AndrodiManifest.xml
Try this.
AndroidManifest.xml have code:

        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.

Editace: 2013-12-09 10:55:08
Počet článků v kategorii: 397

11 Share