can't set text in textview

I have problem with can't set text in UITextView .see below code , TwxtView value not change after setText() . when i press Button "hello word" not change. i want to change "hello world" to "How are you" when i press Button.

public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void showPopup(View view){ final TextView hello = (TextView)findViewById(; System.out.println(hello.getText().toString()); String how = "how are you"; hello.setText(how); System.out.println(hello.getText().toString()); setContentView(R.layout.activity_main); }


<RelativeLayout xmlns:android="" xmlns:tools="" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.popup.MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:onClick="showPopup" android:text="Button" /> </RelativeLayout>

-------------Problems Reply------------

Remove setContentView from showPopup. This is resetting your layout and text view to the original text.

You don't need to set the view twice. Use the following code.

public class MainActivity extends ActionBarActivity {

TextView hello;
protected void onCreate(Bundle savedInstanceState) {
hello = (TextView)findViewById(;

public void showPopup(View view){
String how = "How are you";

Category:java Views:1 Time:2018-11-07

Related post

  • How much text can be set in the TextView, so that it doen't need to scroll 2011-01-24

    How much text can be set in the textview for a particular text string with a particular font and size, so that the textview doesn't need to scroll. I mean how much text can be fit inside an TextView, without the need for scrolling. This is similar to

  • How to set text inside TextView to be in two lines? 2011-10-17

    Is there any way to programmatically set text in TextView to be in two lines ? --------------Solutions------------- Type \n for a new line This will be\ntwo lines will look like This will be two lines Also, be sure that the TextViews setsingleline()

  • How to set Text for TextView so that it will appear from Top left through Code in Android 2010-10-16

    How to set Text for TextView so that it will appear from Top left through Code in Android not by XML. Thanks in Advance? --------------Solutions------------- TextView text = new TextView(context); text.setGravity(Gravity.LEFT|Gravity.TOP); The class

  • Can't change text in textview 2011-04-21

    I have problem with can't set new text in UITextView .I already link up the IBOutlet to textView in interface builder. Here is my code - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Detail"; [self setupTextView]; } - (void) setupTextView {

  • Can I set property of Textview like justify? 2011-05-12

    I want to set TextView property like right align, left align, of justify --------------Solutions------------- No, you can't set the property like gravity. But still you can set the justification to your text by taking webview instead of text view. Yo

  • How Can I Set Text Field Properties Dynamically or Statically in Android 2012-04-23

    How can I set the following two properties for a text field in Android: (Property 1) How can I set a text field that contains some text like "Enter a number" but when it is clicked the text field automatically becomes empty? (Property: 2) Suppose I h

  • Can I set text on a flex Graphics object? 2009-11-03

    Is there anyway I can effectively call the equiv. of setText on a Flex Graphics object ? Specifically I'm using a custom cell renderer to display data in a datagrid. The renderer uses the Graphics object to set the background colour of only a portion

  • How can I set text value of SimpleXmlElement without using its parent? 2010-06-30

    I want to set text of some node found by xpath() <?php $args = new SimpleXmlElement( <<<XML <a> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML ); //

  • how can i change text of TextView in ListView when we click the Button? 2012-01-29

    I have a ListView with a Button and a TextView and i want to change text of TextView when i click in Button. I handle the click and when i click the Button android:onClick="myClickHandler" i change the text value of TextView but the problem is when i

  • How can I set text for cell in UITableview from NSDictionary 2010-08-02

    I have an NSDictionary with 5 keys and corresponding values. How can I set the value in the cell of UITableView when I don't know the key? d=[[NSDictionary alloc] initWithObjectsAndKeys:@"Air Bus",@"ab", @"Boeing 787 ",@"787",@"Some Plane", @"sp",nil

  • Set text on TextView onTextChanged 2011-12-29

    I have a text view defined as class attribute so that I can access it in the entire class. In onCreate method I do the following: chars = (TextView) findViewById(; chars.setText("300"); Later...: public void onTextChanged(CharSequence s, i

  • how can i retrieve text from textview 2011-02-01

    I have a text view with 3 lines of data. eg: abcde efghi jklmn Now i need to retrieve the middle line text(efghi). These 3 lines are unwrap text. How can i can any one please help me. Thank u in advance. --------------Solutions------------- NSString

  • Prevent other views than textview to update/redraw when setting text of textview every second 2012-02-21

    I've got a slightly complicated layout, containing several custom-views that each calculate how much space they need and whatnot. At the top of this layout, I've got a TextView which is supposed to count down from say.. 02:04:20 (hh:mm:ss), and updat

  • Can I set text box to readonly when using Html.TextBoxFor? 2010-03-29

    I have the following tag with a Html.TextBoxFor expression and I want the contents to be read only, is this possible? <%= Html.TextBoxFor(m => Model.Events.Subscribed[i].Action)%> --------------Solutions------------- <%= Html.TextBoxFor(m

  • set text in textview with text from an edittext in another class 2011-09-21

    Im completely new to Android so apologies if this is a silly question. But my problem is this: I have created a number of classes for each of the pages in my app and I would like to update the text in a textview of a particular class from the text in

  • can we set text on RowHeader Column in nebulla Grid in Eclipse RCP? 2011-11-03

    My question : I have a nebulla Grid (org.eclipse.nebula.widgets.grid.Grid) control in my view in Eclipse RCP. I can make the RowHeader of this grid visible by this code : Grid grdTable = new Grid(compParent, SWT.BORDER | SWT.H_SCROLL); grdTable.setRo

  • How can i set text like "Help" and "Support" in android 2011-10-21

    I am new to android. I want to write "Help" & "Support" in xml but an error occure when I am trying to write this in xml . How can I solve this problem. --------------Solutions------------- hi manisha in Xml (") symbol should be written as (&

  • How to set text color to a text view programmatically 2011-12-12

    This question already has an answer here: How to set the text color of TextView in code? 19 answers How can I set Text Color of a text view to #bdbdbd programatically? --------------Solutions------------- Use,.. Color.parseColor("#bdbdbd"); like, mTe

  • Want to change text of TextView from other activity? 2012-02-09

    i am currently designing a ebook reader app as my project, i am having a problem in changing text of the textview from other activity. Contents of my project, Activity 1 contains two buttons and when button1 is clicked "Some Text" Should appear and w

  • How to get styled text from TextView 2013-07-05

    Quite simple problem: I have some TextView TextView textView = (TextView) findViewById(; I set styled text (with <b> tags or any other tags) textView.setText(Html.fromHtml("Simple text. <b>Bold text</b>. Simple text."

  • php SimpleXMLElement set text 2010-06-03

    how to set text for a SimpleXMLElement in php? --------------Solutions------------- Did you look at the basic documentation examples? From there: include 'example.php'; $xml = new SimpleXMLElement($xmlstr); $xml->movie[0]->characters->charac

  • How to set text in file (html input type) 2010-12-07

    please tell me how can we set text in html file uploader. is it possible using javascript? if their is any way plez tell me. Thanks --------------Solutions------------- You cannot. The value attribute is ignored, and the DOM value property is readonl

  • WatIn: Problem in setting text for Body 2011-05-23

    I'm trying to put text in editable field of body type. As body doesn't have anything similar to type text. I'm not able to do it. I have already seen one question (

  • UIPicker won't set text field 2012-04-08

    I have a custom Picker with country list and corresponding flags everything work fine, but i want when country is selected country name and the flag as background picture to be displayed and i don't understand why my method can't set text a text it's

Copyright (C), All Rights Reserved.

processed in 0.144 (s). 11 q(s)