I have figured out the solution. It is slightly twisted.... Below is the solution...
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:id="@+id/simple_activity_root" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical" > <TextView android:id="@+id/simple_activity_textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Simple Activity Started" /> </LinearLayout> Java Code: LayoutInflater inflater = (LayoutInflater)this.getSystemService (Context.LAYOUT_INFLATER_SERVICE); View inflatedView = inflater.inflate (R.layout.simple_activity,l,true); LinearLayout ly = (LinearLayout) inflatedView.findViewById (R.id.simple_activity_root); TextView tv = (TextView)inflatedView.findViewById (R.id.simple_activity_textview); ly.removeView(ly.findViewById(R.id.simple_activity_textview)); setContentView(tv); So basically I had to inflate the layout. Pick out the linear layout. Then pick the textview. Then remove the textview from the LinearLayout. Then the textview can be set as a content view... huff... On Sep 26, 11:41 pm, amit <amitkee...@gmail.com> wrote: > hi, > > I see a strange problem when I try to set a TextView, instead of a > layout file via setContentView. > > Case 1: > i.e. if I do the following, it works fine... > > TextView tv = new TextView(this); > tv.setText("Hello World"); > setContentView(tv); > > Everything is OK. > > Case 2: > But suppose I have a main.xml file with a TextView in it and I try the > following: > > =========== > View tv = findViewById(R.id.textview); > setContentView(tv); > =========== > I get a Force Close with the below error > > 09-27 00:08:26.620: ERROR/AndroidRuntime(1595): Caused by: > android.content.res.Resources$NotFoundException: Resource ID > #0x7f050001 type #0x12 is not valid > 09-27 00:08:26.620: ERROR/AndroidRuntime(1595): at > android.content.res.Resources.loadXmlResourceParser(Resources.java: > 1801) > 09-27 00:08:26.620: ERROR/AndroidRuntime(1595): at > android.content.res.Resources.getLayout(Resources.java:685) > 09-27 00:08:26.620: ERROR/AndroidRuntime(1595): at > android.view.LayoutInflater.inflate(LayoutInflater.java:318) > 09-27 00:08:26.620: ERROR/AndroidRuntime(1595): at > android.view.LayoutInflater.inflate(LayoutInflater.java:276) > 09-27 00:08:26.620: ERROR/AndroidRuntime(1595): at > com.android.myhelloworld.SimpleActivity.onCreate(SimpleActivity.java: > 22) > > Case 3: I even tried to inflate the xml and set the view but even that > resulted in a force close. > > Am I missing something here ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---