[android-developers] Re: How to create TextView without write the XML file
Thanks for the suggestions San and Fllip. I have tried the example that San gave but still errors. Here's the revised code in the main.xml file: 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 tv = (TextView) findViewById(R.id.TextView01); 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(); tv.setText(Button Clicked); } }); } } Errors are: for the line: tv = (TextView) findViewById(R.id.TextView01); tv can not be resolved to a variable for the line: tv.setText(This is sample.); tv can not be resolved for the line: tv.setText(Button Clicked); tv can not be resolved Any ideas why the errors? On Aug 31, 4:56 pm, San sanees...@gmail.com wrote: As Havlicek said, create thetextviewusing findViewByID and set the text when button is clicked. Sample code: tv = (TextView) findViewById(R.id.TextView01); tv.setText(This is sample.); Button button = (Button) findViewById(R.id.Button01); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { tv.setText(Button Clicked); } }); -- 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
[android-developers] Re: How to create TextView without write the XML file
As a newbie, I am just trying to program the various functions to ensure that I am doing things right (gui wise). An example would be to set a default template with textview, editview, buttons, etc and just changing the parameters of those objects either by direct (as by this code) or by calling a class (method). I have done this with standard java but not in a gui environment. That is why I have created this simple Hello World example, and attempting to add other objects to see if I can make it work once it is compiled. Hope this answers your question. On Aug 31, 4:59 am, parag parag.shetgaon...@gmail.com wrote: Any suggestions on why I am getting the false reading -- in the xml , set the button propert android:clickable as true, anyone can suggest on how to place the results in aTextViewvia a button click, that would be appreciated. as i can c u have the listener to the button, on click can u be specific what exact result u need? wether u need to change the text... etc. u can use tv.XXX specifically to change the required properties -- 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
Re: [android-developers] Re: How to create TextView without write the XML file
You still need to specify the tv variable type (of course, think about it!!!). TextView tv = (TextView) findViewById(R.id.TextView01); Best regards, Filip Havlicek 2010/9/1 rb rbs...@gmail.com As a newbie, I am just trying to program the various functions to ensure that I am doing things right (gui wise). An example would be to set a default template with textview, editview, buttons, etc and just changing the parameters of those objects either by direct (as by this code) or by calling a class (method). I have done this with standard java but not in a gui environment. That is why I have created this simple Hello World example, and attempting to add other objects to see if I can make it work once it is compiled. Hope this answers your question. On Aug 31, 4:59 am, parag parag.shetgaon...@gmail.com wrote: Any suggestions on why I am getting the false reading -- in the xml , set the button propert android:clickable as true, anyone can suggest on how to place the results in aTextViewvia a button click, that would be appreciated. as i can c u have the listener to the button, on click can u be specific what exact result u need? wether u need to change the text... etc. u can use tv.XXX specifically to change the required properties -- 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.comandroid-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
[android-developers] Re: How to create TextView without write the XML file
I knew there was something that I missed. Thanks to all who shed light on this thread. Here's the final code for those newbies who may have the same problem. 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 // declare tv object by findViewByID final TextView tv = (TextView) findViewById(R.id.TextView01); // set TextView's text property to a new string upon launch of app tv.setText(This is sample.); // declare button object by findViewByID Button button = (Button) findViewById(R.id.Button01); // Method if you click the button button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // this is a pop up message then goes away after a short period of time Toast.makeText(Hello.this, Hello World, Toast.LENGTH_SHORT).show(); // this changes the text in the TextView object to the said string tv.setText(Button Clicked); } }); } } On Sep 1, 2:26 am, Filip Havlicek havlicek.fi...@gmail.com wrote: You still need to specify the tv variable type (of course, think about it!!!). TextView tv = (TextView) findViewById(R.id.TextView01); Best regards, Filip Havlicek 2010/9/1 rb rbs...@gmail.com -- 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
[android-developers] Re: How to create TextView without write the XML file
Any suggestions on why I am getting the false reading -- in the xml , set the button propert android:clickable as true, anyone can suggest on how to place the results in a TextView via a button click, that would be appreciated. as i can c u have the listener to the button, on click can u be specific what exact result u need? wether u need to change the text... etc. u can use tv.XXX specifically to change the required properties On Aug 28, 8:28 pm, rb rbs...@gmail.com wrote: 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 For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to create TextView without write the XML file
As Havlicek said, create the textview using findViewByID and set the text when button is clicked. Sample code: tv = (TextView) findViewById(R.id.TextView01); tv.setText(This is sample.); Button button = (Button) findViewById(R.id.Button01); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { tv.setText(Button Clicked); } }); On Aug 31, 4:59 am, parag parag.shetgaon...@gmail.com wrote: Any suggestions on why I am getting the false reading -- in the xml , set the button propert android:clickable as true, anyone can suggest on how to place the results in a TextView via a button click, that would be appreciated. as i can c u have the listener to the button, on click can u be specific what exact result u need? wether u need to change the text... etc. u can use tv.XXX specifically to change the required properties On Aug 28, 8:28 pm, rb rbs...@gmail.com wrote: 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.- Hide quoted text - - Show quoted text - -- 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