Instead of creating new TextView, get the one you declared in main.xml by calling findViewById the same way you are doing with the button.
Best regards, Filip Havlicek 2010/8/28 rb <rbs...@gmail.com> > As a newbie, I have been reading posts in learning how to do different > functions. Using the Hello World example, I added a textview object > to this application but the results come back as false on the screen. > Here's my code: > > main.xml: > > <?xml version="1.0" encoding="utf-8"?> > > <RelativeLayout android:id="@+id/RelativeLayout01" > android:layout_width="fill_parent" android:layout_height="fill_parent" > xmlns:android="http://schemas.android.com/apk/res/android"> > <Button android:id="@+id/Button01" > android:layout_width="wrap_content" > android:layout_height="wrap_content" android:text="Click Me" > android:layout_centerInParent="true"></Button> > <TextView android:text="@+id/TextView01" > android:id="@+id/TextView01" > android:layout_below="@id/Button01" > android:layout_height="wrap_content" > android:layout_width="fill_parent"></TextView> > </RelativeLayout> > > --------------------------------------------------------------------------------------------------------------------------------- > Hello.java > > package com.HelloWorld; > > import android.app.Activity; > import android.os.Bundle; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.TextView; > import android.widget.Toast; > > public class Hello extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > // start code here > TextView tv = new TextView(this); > tv.setText("This is sample."); > Button button = (Button) findViewById(R.id.Button01); > button.setOnClickListener(new OnClickListener() { > public void onClick(View v) { > // TODO Auto-generated method stub > Toast.makeText(Hello.this, "Hello World", > Toast.LENGTH_SHORT).show(); > > } > }); > } > } > > > --------------------------------------------------------------------------------------------------------------------------------- > Note that the example included a clickable button which has a popup to > say "Hello World". That works just fine, but setting the text in the > TextView comes out as false. Originally I wanted to click on the > button and present the results in a TextView, but I was unable to do > that unless someone can shed some light on that. > > Any suggestions on why I am getting the "false" reading and if anyone > can suggest on how to place the results in a TextView via a button > click, that would be appreciated. > > -- > 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<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- 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