Floating Action Button does not raise OnClick event

风流意气都作罢 提交于 2019-12-04 11:35:32

Try this:

fab.bringToFront();

Should help.

The solution suggested by @Tasos worked:

add a click event inside the xml e.g

android:onClick="runThis"

and then in the Activity add

public void runThis(View v) { ..... }

I experienced the same problem when I failed to return the View object, but instead made another call to infalter.inflate like this:

View rootView = inflater.inflate(R.layout.fragment_main, container, false);
/* setup onClick handler */
return inflater.inflate(R.layout.fragment_main, container, false);

The fix was replacing the return with

return rootView;

I actually found the following solution to deal with lost clicks

public class MainActivity extends AppCompatActivity implements View.OnClickListener 
{
    @Override
        public void onClick(View v) {
            Log.v(LOG_HEADER,"onClick");       
        }
}

public class SearchFragment extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        LinearLayout ll = (LinearLayout )inflater.inflate(R.layout.fragment_search, container, false);
        ll.setOnClickListener((MainActivity)getActivity());
        return ll;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!