cocos2d ccsprite in front or top of android xml layout - android

want to add CCSprite on button click of android xml layout , this CCSprite must be in front of that layout button. Please help me out
holder.buttonDonate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// ClanCastleDonateUI extends CCLayer and it contains CCSprite
ClanCastleDonateUI troopDonatePopup = new ClanCastleDonateUI(message2);
troopDonatePopup.setAnchorPoint(0.5f, 0.5f);
troopDonatePopup.setPosition(HowUtils.getScreenSize().x/2, HowUtils.getScreenSize().y/2);
troopDonatePopup.setVertexZ(50);
CCDirector.sharedDirector().getRunningScene().addChild(troopDonatePopup, 9999999);
}
});

Please be more specific. according to what i understand , do you need to change the button when clicked. or do you have to place a new sprite on the screen when a button is clicked.

Related

Android transform ImageView to Button programmiticaly with two images and onClickListener

I want to create a button animation with two image on an ImageView programmiticaly only and by using onClickListener. I have two image that i can set with setImageResource() fonction but i don't know how to play the button animation before the button action launches.
Please, could you explain a bit more what you are wanting? Do you want to replace the ImageButton resource when you click on it? You can achieve it setting the OnClickListener
new View.OnClickListener() {
public void onClick(View v) {
imageButtonView.setImageResource(idOfTheNewResource);
}
};
Is this what you are wanting?

AchartEngine disable only zoomout button

I'm using AchartEngine to draw graphs,
is it possible to disable only the zoom out button ?
thanks.
You can disable the original zoom buttons with below code
mRenderer.setZoomButtonsVisible(false);
and write your own button just to zoom-in inside your xml file and do something like below:
ImageButton btnZoomIn= (ImageButton) findViewById(R.id.btnZoomIn);
btnZoomIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mChartView.zoomIn();
}
});

I need create a button in java class and replace it in xml

I need create a button in java class and replace it in xml in a specific position like i want to put them in horizontal scrollView that i created in xml please any help + i need a function the allow me to generate button automatically according to my array size thanks. .
Try This code
LinearLayout layout=(LinearLayout)findViewById(R.id.linearLayout);
LayoutParams layoutParam_text=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); layoutParam_text.gravity=Gravity.LEFT;
Button btnTest[]=new Button[array.size];
for(int i=0;i<array.size();i++)
{
btnTest[i] =new Button(this);
btnTest[i].setLayoutParams(layoutParam_text);
btnTest[i].setTag(""+i);
btnTest[i].setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
}
});
layout.addView(btnTest[i]);
}

Change zoom controls in a MapView

I would like to change the predefined style of the zoom controls in my application to appear like the new zoom controls in the google maps application. See below:
How can I do it? I have been looking around and I haven't found anything.
Thanks in advance.
You should have four image drawables namely:
Zoom in (+) enable/disable
Zoom out (-) enable/disable
Put them in MapView layout an ImageView or Button with background image as the above drawables.
Then you should assign onClickListeners like:
zoomIn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mapView.getController.zoomIn()
checkzoom();
}
});
zoomOut.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mapView.getController.zoomOut()
checkzoom();
}
});
public void checkzoom() {
if(mapView.getZoomLevel()==1) // dont know if 0 or 1, just wrote it
{
zoomOut.setEnabled(false);
// or u can change drawable and disable click
}
if(mapView.getZoomLevel()==18) {
zoomIn.setEnabled(false);
// or u can change drawable and disable click
}
}
EDIT:
I solved the problem this way: disabled built in zoom controls (setBuiltInZoomControls(false)), added my own buttons to UI and added handlers for click on button events.

In Android: How do you show layout twice using intent?

Let's pretend this was my Java Class...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ScreentwoGameButton = (Button) findViewById(R.id.screentwo);
ScreentwoGameButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent ScreentwoGameIntent = new Intent(Main.this, Screentwo.class);
startActivity(StartGameIntent);
}
});
How do i use this code below but the right way like.
So let's put an example if I click screentwo button the screentwo.xml will show and it will allow me to click inside if any buttons are available. Instead just stare what's in the layout.
I don't want to use the Activity to activity cause the whole point is i'm trying to avoid the flashing looking feel going to another java class.
If you look at the moron test game on Android it says example: press the blue button then red and then green, so if u press the blue button the screen will remain and not flash at all but the image of the blue button will disappear and I'm allowed to click the red and then green.
Hope that helped.
Thanks
Wahid
Button ScreentwoButton = (Button) findViewById(R.id.screentwo);
ScreentwoButton.setOnClickListener(new OnClickListener() {
private Uri Uri;
#Override
public void onClick(View v) {
setContentView(R.layout.Screentwo);
Uri uri=Uri;
Intent i=new Intent(Intent.ACTION_VIEW, uri);
mSoundManager.playSound(1);
}
});
try to use:
setContentView(R.layout.next layout); in your button click.
You could use the viewflipper class and add the different layouts as childs to the viewflipper
and set the active child. Using setcontentView will be trouble some when you use findViewById for a old layout. As findViewById will look in the layout that is specified by setContentView

Categories

Resources