0

I want to display a certain text to be displayed when a button is clicked in a new page but the only thing showing up is the default "TextView"

This is the page before the display. so once they click the one button it takes them to the next page showing them there results

public class Option1 extends Activity implements OnClickListener{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.option1);

    Button butn1 = (Button) findViewById(R.id.button1);
    butn1.setOnClickListener(this);
}

@Override
public void onClick(View v) {

    Intent intent = new Intent(this,Display.class);

    intent.putExtra("Option", "Choice1");
    startActivityForResult(intent, 1);

    this.startActivity(intent);
}   

}

once they press the button on the previous page i want it to show what they picked depending on what button was clicked but its not showing they new text in the TextView area

public class Display extends Activity implements OnClickListener{



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.display);

    //It works if i just have this part

    //TextView tv = (TextView) findViewById(R.id.textView1);
    //tv.setText("Exterior" + "\nOption1");
}

@Override
public void onClick(View v) {

Intent intent = getIntent();
String msg = intent.getStringExtra("Option");

if (msg.contentEquals("Choice1")){

    TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setText("Exterior" + "\nOption1");

}
else if (msg.contentEquals("Choice2")){

}
}

}

8
  • What is your issue..? What happened when you execute the above code
    – Pragnani
    Apr 18, 2013 at 18:46
  • What is not working with this code? LogCat error?
    – TronicZomB
    Apr 18, 2013 at 18:46
  • How can you press a new button on an XML?
    – m0skit0
    Apr 18, 2013 at 18:46
  • sorry i didn't specify enough, it wont show my message that i want it to just show the default "TextView".
    – Dazed
    Apr 18, 2013 at 18:48
  • You might benefit from reading the android fragment tutorials as this will teach you the best way to do a complex hide-n-show
    – petey
    Apr 18, 2013 at 18:53

2 Answers 2

0

You should have the TextView be invisible in xml

 if (msg.contentEquals("Choice1")){

    TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setVisibility(View.VISIBLE);
    tv.setText("Exterior" + "\nOption1 ");

 }
0

If you want a certain text on the next page with new xml, send the text as intent.putExtra to the next activity which holds the new xml and there you can display it,within the onCreate method of the new Acivity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.