I am new to android apps. I am using the netbeans 7.0.1 IDE to develop android apps. I have written the following code in the main java file:
package com.test.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class helloworld extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView t1=new TextView(this);
t1.setText("hello world..!!!!");
setContentView(t1);
}
}
This was working fine.
I edited the main.xml file to display a textfield and button as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"/>
<EditText android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message"/>
</LinearLayout>
Of course I have added all the corresponding strings in strings.xml. But when I try to run my app these weren’t displaying… 🙁 . I mean the same string that was displayed previously was being displayed.
Can anybody figure out what is the mistake??
Remove below lines from onCreate method of your activity
Because you are setting the
contentViewfrom themain.xmland then again you are creating the TextView dynamic and setting that TextView as a contentView. so you are getting the static string"hello world..!!!!"Edit
There is a spelling mistake in your
android:oreintationline which you are using for set orientation. use “android:orientation” instead.