I would like to have a popup contextual help when the user clicks a button in a FRAGMENT of an activity. I have tried using the Toast
to perform this action but in vain. The popup dialog box does not show (please also note that the recommendations in Use Toast inside Fragment did not help).
My code in the fragment class is written below:
final Button help = (Button) view.findViewById(R.id.help_button);
del.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Context context = (TabsActivity) getActivity().getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(view.getContext(), text, duration);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
}
});
I have tried several variations of CONTEXT
, two of which are shown in the code.
I have also tried getActivity()
, getView().getContext()
, getContext()
all of which went in vain. Can you please help understanding how to set the CONTEXT in a fragment?