I am trying to use a floating action button in a fragment to bring up a dialog to create a new post. The issue I am having is that I get an error on this line of code:
popAddPost = new Dialog(this);
The error states that:
Dialog (android.content.context) in Dialog cannot be applied to (com.comhar.firebaseapp.Fragments.ForumFragment)
I have tried using a few solutions i found online but none have worked
ForumFragment.java
public class ForumFragment extends Fragment {
Dialog popAddPost;
public ForumFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_forum, container, false);
iniPopup();
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popAddPost.show();
}
});
return view;
}
private void iniPopup() {
popAddPost = new Dialog(this);
popAddPost.setContentView(R.layout.popup_add_post);
popAddPost.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popAddPost.getWindow().setLayout(Toolbar.LayoutParams.MATCH_PARENT,Toolbar.LayoutParams.WRAP_CONTENT);
popAddPost.getWindow().getAttributes().gravity = Gravity.TOP;
}
}
fragment_forum.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.ForumFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="forum" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="20dp"
android:src="@drawable/nep_post" />
</FrameLayout>
The app will not run as I am recieving the error:
error: incompatible types: ForumFragment cannot be converted to Context
any advice would be greatly appreciated!