Please, find below a possible way how you could implement the logic.
If you have problems with filling out the missing code, feel free to
contact me.
- use button.setText to change the text on a button
- use findViewById( ) to change the resource id
public class ButtonSwap extends Activity implements OnClickListener
....
protected Button button1, button2;
protected boolean mSwitch = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//button
button1 = (Button)findViewById(R.id.Button01);
button2 = (Button)findViewById(R.id.Button02);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
...
}
public void onClick(View v) {
if (v.getId() == button1.getId()) {
Log.d(TAG,"you pressed button 1");
}
else if (v.getId() == button2.getId()) {
Log.d(TAG,"you pressed button 2");
}
mainLogic();
}
void mainLogic(){
Log.d(TAG,"switch:"+mSwitch);
//we swap the text on the buttons
if(mSwitch){
Log.d(TAG,"TRUE");
//change the resource Id for the buttons
}
else{
Log.d(TAG,"FALSE");
//change the resource Id for the buttons
}
mSwitch = !mSwitch;
}
--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.
On Aug 11, 12:49 pm, Calve Martin <[email protected]> wrote:
> Hi,
>
> I'm new to Android development. I want to create Two rectangle button
> on my application. I want to apply swapping logic for that two
> buttons. For ex: When i press first button it should move to second
> button and second button will come to first button place.
> How to do that in Android? Can anyone please provide me the links
> where i can go and directly catch that logic?
> Note: I know about developer.android.com website already.
>
> thanks.
>
> Calve.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---