Use
Activity activity = (Activity) context;
activity.startActivityForResult(intent, REQUEST_PICK_FILE);
Question
I'm trying to implement File Picker in preferences(I could not find it). So, there are Button and TextView. I need to show file dialog, when user click the button. So, I have to invoke startActivityForResult function from my preferences.xml.
Some code:
@Override
protected View onCreateView(ViewGroup parent){
LinearLayout layout = null;
try {
LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (LinearLayout)mInflater.inflate(R.layout.file_picker_preference, parent, false);
selectFileButton = (Button)layout.findViewById(R.id.file_picker_button);
selectFileButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), FilePickerActivity.class);
startActivityForResult(intent, REQUEST_PICK_FILE);//I CANNOT INVOKE THIS!!!!!
}
});
}
catch(Exception e)
{
}
return layout;
}
How can I do this? Or if there is some implementation of FilePicker, it will be the best answer.
Solution
Use
Activity activity = (Activity) context;
activity.startActivityForResult(intent, REQUEST_PICK_FILE);