Back to project page surveygcp.
The source code is released under:
GNU General Public License
If you think the Android project surveygcp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.droidplanner.gcp.dialogs.openfile; /* w ww .ja v a2 s . com*/ import org.droidplanner.gcp.R; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.widget.Toast; public abstract class OpenFileDialog implements OnClickListener { public interface FileReader { public String getPath(); public String[] getFileList(); public boolean openFile(String file); } protected abstract FileReader createReader(); protected abstract void onDataLoaded(FileReader reader); private String[] itemList; private Context context; private FileReader reader; public void openDialog(Context context) { this.context = context; reader = createReader(); itemList = reader.getFileList(); if (itemList.length == 0) { Toast.makeText(context, R.string.no_files, Toast.LENGTH_SHORT) .show(); return; } AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setTitle(R.string.select_file_to_open); dialog.setItems(itemList, this); dialog.create().show(); } @Override public void onClick(DialogInterface dialog, int which) { boolean isFileOpen = reader .openFile(reader.getPath() + itemList[which]); if (isFileOpen) { Toast.makeText(context, itemList[which], Toast.LENGTH_LONG).show(); } else { Toast.makeText(context, R.string.error_when_opening_file, Toast.LENGTH_SHORT).show(); } onDataLoaded(reader); } }