我正在尝试在首选项中实现文件选择器(我找不到它)。所以,有Button和TextView。当用户单击按钮时,我需要显示文件对话框。所以,我必须从我的preferences.xml调用startActivityForResult函数。
一些代码:
@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;
}
我该怎么做?或者如果有一些FilePicker的实现,它将是最好的答案。
答案 0 :(得分:0)
使用
Activity activity = (Activity) context;
activity.startActivityForResult(intent, REQUEST_PICK_FILE);