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.

Include xml into another xml Android Example


AD MOB

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

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

397LW NO topic_id




AD

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


288

Eclipse - Java was started but returned exit code=13 | eclipse-java-was-started-but-returned-exit-code13


Windows 7 64-bit version.
Eclipse 64-bit - Java was started but returned exit code=13

Solution:
Download and install 64-bit version of JDK
//www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
11

Number convert int to string Java Android example code | number


Convert number int to string Android Java example source code.

int n = 0;

try {
    n = Integer.parseInt("21"));
} catch(NumberFormatException e) {
   System.out.println("Could not parse " + e);
} 
// int to string
String s = String.valueOf(24);
211

The container JRE System Library JavaSE references non existing library | the-container-jre-system-library-javase-references-non-existing-library


Eclipse Error: The container JRE System Library JavaSE references non existing library QTJava.zip

Workaround:
Windows->Preferences->Java->Installed JRE
Press Add and select your JRE folder path for example:
c:\Program Files\Java\jre7\
and check your choice.

eclipse instaled jres path dialog
246

Set Custom Font to View Android Example | set-custom-font-to-view-android-example


You have to put your font fonts/samplefont.ttf into assets/fonts folder in your project!

// set own custom font from assets
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface mFace = Typeface.createFromAsset(getContext().getAssets(),
                                             "fonts/samplefont.ttf");
    txt.setTypeface(mFace);
31

Start Activity from ListView item click Android example | 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 {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        try {
        setContentView(R.layout.main);
        
			ListView mlistView = (ListView) findViewById(R.id.idListView);
			mlistView.setAdapter(new ArrayAdapter<String>(this,
			        android.R.layout.simple_list_item_1, 
			        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(),
                  Toast.LENGTH_SHORT).show();
              String sText = ((TextView) view).getText().toString();
              Intent intent = null;
              if(sText.equals("Game"))
              intent = new Intent(getBaseContext(),
						Game.class);
              //else if(sText.equals("Help")) ..........

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



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

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





package cz.okhelp.listview;

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

public class Game extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // you have to create game.xml 
        setContentView(R.layout.game);
    }
}






Editace: 2013-01-06 10:41:45
Počet článků v kategorii: 397
Url:include-xml-into-another-xml-android-example

AD
11 Share
Share
Tweet