Reputation: 559
I am a newbie. Getting error:
Cannot resolve method 'makeText'
I am using navigation drawer and My class name is MainFragment.java
.
Actually I was to trying to use File and Folder Explorer, only this error.
What I have tried: Tried using MainFragment.getContext()
and getActivity()
and context
and this
, in-place of MainFragment.this
but none is working.
MainFragment.java
public class MainFragment extends Fragment
{
//Defined for file edittext.
EditText editText2;
public MainFragment() {
// Required empty public constructor
}
/* @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_main, container, false);
}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_main, container, false);
Button dirChooserButton = (Button) view.findViewById(R.id.skipButton); //Browse Button
dirChooserButton.setOnClickListener(new OnClickListener()
{
private String m_chosenDir = "";
private boolean m_newFolderEnabled = true;
@Override
public void onClick(View v)
{
// Create DirectoryChooserDialog and register a callback
DirectoryChooserDialog directoryChooserDialog =
new DirectoryChooserDialog(MainFragment.this,
new DirectoryChooserDialog.ChosenDirectoryListener()
{
@Override
public void onChosenDir(String chosenDir)
{
m_chosenDir = chosenDir;
Toast.makeText(
getActivity(), "Chosen directory: " +
chosenDir, Toast.LENGTH_LONG).show();
}
});
// Toggle new folder button enabling
directoryChooserDialog.setNewFolderEnabled(m_newFolderEnabled);
// Load directory chooser dialog for initial 'm_chosenDir' directory.
// The registered callback will be called upon final directory selection.
directoryChooserDialog.chooseDirectory(m_chosenDir);
m_newFolderEnabled = ! m_newFolderEnabled;
}
});
@Override
public void onChosenDir(String chosenDir)
{
m_chosenDir = chosenDir;
Toast.makeText(MainFragment.this, "Chosen directory: " +chosenDir,Toast.LENGTH_LONG).show();
}
}
}
Actually I tried this link for making File and Folder Chooser: link to the webpage
Upvotes: 0
Views: 2154
Reputation: 21
try this one Toast.makeText( MainActivity.this,"Data Inserted", Toast.LENGTH_SHORT).show();
Here Mainactivity is the name of class
Upvotes: 0
Reputation: 731
Fragment will not be able to show your toast, it has to come from activity. Try the following:
Toast.makeText(getActivity(), "Chosen directory: " + chosenDir, Toast.LENGTH_LONG).show();
Upvotes: 1