Android UI XML Layout – Education Career Blog

I’ve created textview layout into main.xml, i want to see effects onto emulator, but i did not get my changes, it shows old result when i run my app into emulator…..

eg:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/textview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="@string/hello"/>

strings:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello, Android! I am a string resource!</string>
    <string name="app_name">Hello, Android</string>
</resources>

Please help if anyone know…………..

,

You probaly need to set the contentView of your Activity using the setContentView() to point to the new layout

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
   }
}

See more under “Upgrade the UI to an XML Layout”
http://developer.android.com/resources/tutorials/hello-world.html

,

If you want dynamically change the text in your text view you need:

  • set the content view for your activity:

    setContentView(R.layout.main);
    
  • get a reference to the TextView object:

    TextView tv= (TextView)findViewById(R.id.textview);
    
  • assing a new value:

    tv.setText(R.string.app_name);
    

Leave a Comment