Button click event not firing in second view of a viewflipper

寵の児 提交于 2019-12-11 01:53:21

问题


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:

  1. 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.

  2. 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 correctly 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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3065505/button-click-event-not-firing-in-second-view-of-a-viewflipper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!