2

Possible Duplicate:
How to store and display the button names ( in different screens)that are clicked by user in android

I have several buttons in one screen ,I want to that only clicked button names should be displayed in next screen.

How can I do this?

Community
  • 1
  • 1

3 Answers3

0

I assume you mean "How do you start the next screen and display the name when pressing the button?"... If so, you can use the onClickListener of the button (or the method defined in the onClick property of the xml for the button) to start an intent.

gh.
  • 339
  • 1
  • 3
  • 20
  • Rereading your post, I see you want several names passed to the next screen, see the link above also for passing data to your intent. – gh. Sep 05 '12 at 19:38
  • i clicked on button1 in screen1 then screen2 rendered,i clicked on button2 in screen2 then screen 3 rendered in the screen3 i would like to display the two button names –  Sep 05 '12 at 19:41
  • If you are starting intents to render the next screen, pass the button names along with intent.putExtra(extra-stuff-here); before you use myIntentName.start(); If you are just changing screens from your java code, that button information should be readily available, which is why I assume you are using intents. If not please explain more about what you are doing to "render next screen" – gh. Sep 05 '12 at 19:46
  • Button switchButton6 = (Button) findViewById(R.id.pickitem7); switchButton6.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, PickHeatActivity.class); startActivity(intent); } }); –  Sep 05 '12 at 19:48
  • Intent intent = new Intent(context, PickHeatActivity.class); startActivity(intent); –  Sep 05 '12 at 20:02
  • for rendering screen i am using this –  Sep 05 '12 at 20:03
  • 1
    So see the link in my original answer, and my second comment above. Use intent.putExtra to pass data from your existing activity to the activity you are starting with the intent. That link and your favorite search engine should provide a wealth of information. – gh. Sep 05 '12 at 23:08
0

What gh is saying is you need to add

intent.putExtra("someKey", "someValue");

before the startActivity(). Then, in the next activity, you can do:

String someVariable = getIntent().getStringExtra("someKey");

and you can display someVariable in a TextView or however you want to do that. Just keep passing the values with the intent.

codeMagic
  • 44,549
  • 13
  • 77
  • 93
0

Declare a static String to store the name of the button which was clicked.

public static String buttonName;

Now, whenever any button is clicked, add the name of that button in the String.

 myButton.setOnClickListener(new OnClickListener() 
{ @Override 
public void onClick(View v) 
{ buttonName = "myButtonNumberX";
Intent intent = new Intent(context, PickHeatActivity.class); 
startActivity(intent); } 
}
);

Then, in your new PickHeatActivity, you can just access the name of the button by using MyMainActivityName.buttonName.

Swayam
  • 16,294
  • 14
  • 64
  • 102