views:

41

answers:

2

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..............

A: 

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

madsleejensen
hi folks, i'm new to android i've simple created a HelloAndroid application i want to try with xml layout. i've done it through developer guideline but after running the app it does not show the content that i've written into string.xml
abhay
A: 

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);
    
Asahi
Could you tell me the meaning of "v." in this line TextView tv= (TextView)v.findViewById(R.id.textview);?
abhay
oops, missed it. meant to write just findViewById().
Asahi