Button click event not firing in second view of a viewflipper
I have a layout in xml that, when the user clicks a "next" button I inflate, populate with the next screen's data, and create and set the onclicklistener for an imagebutton in the new view. I then add this view to my main ViewFlipper and call showNext() on it. The view slides into place and the button is there but there are problems:
The button image is a square but is transparent so the only viewable part is a circle, except when the second view gets shown you see a gray square button with a circle on top of it.
The click event never fires. The gray square changes color to indicate a click (not the circular portion that is what should be seen and if it were working co开发者_Python百科rrectly would have its color changed) but the onClick event in the listener never executes.
This works perfectly the first time I do this procedure (inflate, create onClickListener, add to ViewFlipper- although the first time I don't call showNext obviously).
Anyone seen anything like this? It's driving me crazy
Removing the in / out animations from your ViewFlipper, or alternatively settings:
android:fillAfter="false"
android:fillBefore="false"
on your in / out animations will solve the problem and you'd be able to use the standard XML defined onClick listeners.
I just spent the last four hours figuring this out. I think it's just a work around, but it gets me to the place where I can get my button clicks for views further than the first one.
In your xml, use --
android:onClick="onClick"
Then in your code, use the below format for listening to your button events..
public void onClick(View vw)
{
switch (vw.getId())
{
case R.id.continue_button:
if(verifyAllTasksCompleted()){
currentPage++;
updateView();
}
break;
Hope this helps you. Iris
精彩评论