I have a floating action button in my layout, and I would like it to open another view when clicked. I read from this answer that a good way to handle click events was this:
public class AllTasksFragment extends Fragment implements OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_all_tasks, container, false);
FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
fab.setOnClickListener(this);
return rootView;
}
@Override
public void onClick(View rootView) {
switch (rootView.getId()) {
case R.id.fab:
setContentView(R.layout.fragment_new_task);
break;
}
}}
But, because setContentView
method can't be used in fragments, Android Studio returns an error: Cannot resolve method setContentView(int)
.
What can I use instead of setContentView to bring up another view through onClick method? Or do I have to approach this in a completely different way?