{"id":203884,"date":"2013-11-28T08:20:06","date_gmt":"2013-11-28T04:20:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=203884"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=203884","title":{"rendered":"<span class=\"post_title\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e OpenFileDialog \u0434\u043b\u044f Android<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043a\u0430\u043a \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u043e\u0434 <b>Android<\/b>, \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0434\u043d\u044f\u0445 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u044b\u0431\u043e\u0440 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0422\u0430\u043a \u043a\u0430\u043a \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432 <b>Android<\/b> \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0435\u0442, \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u043a <a href=\"https:\/\/www.google.ru\/\">\u0432\u0435\u043b\u0438\u043a\u043e\u043c\u0443 \u0438 \u0443\u0436\u0430\u0441\u043d\u043e\u043c\u0443<\/a>. \u042d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c, \u043d\u043e \u0438\u0437 \u0432\u043e\u0440\u043e\u0445\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 <a href=\"http:\/\/stackoverflow.com\/\">stackoverflow<\/a> \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u0443\u043c\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430:  <\/p>\n<ol>\n<li> <a href=\"https:\/\/code.google.com\/p\/android-file-dialog\/\">Android File Dialog<\/a> \u2013 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 stackoverflow \u0432\u0435\u0434\u0443\u0442 \u0441\u044e\u0434\u0430. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e <b>activity<\/b>, \u0430 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0447\u0435\u0433\u043e-\u0442\u043e \u0432 \u0434\u0443\u0445\u0435 <b>OpenFileDialog<\/b>\u2019\u0430 \u0438\u0437 <b>.Net<\/b>.<\/li>\n<li>\u0412 <a href=\"http:\/\/habrahabr.ru\/post\/109486\/\">\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u0431 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0430\u0439\u043b-\u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0435, \u0438 \u043f\u043e\u0447\u0435\u0440\u043f\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u0434\u0435\u0438 \u0438\u0437 \u043d\u0435\u0451 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c.<\/li>\n<li>\u0418\u0434\u0435\u044f \u0436\u0435 <a href=\"http:\/\/www.wtg.ru\/products\/onlinedev\/031\/\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c, \u043e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435.<\/li>\n<\/ol>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043d\u0430\u0447\u0430\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u0410 \u043f\u043e\u0441\u0435\u043c\u0443, \u0440\u0435\u0448\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0430 \u0432\u0441\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u0432\u0435\u043b\u0438. \u0416\u0435\u043b\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0439\u0442\u0438 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u2013 <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c! \u0412 \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e <b>IntelliJ IDEA<\/b>) \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 <b>activity<\/b> \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u043e\u0434\u043d\u0443 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a \u043d\u0435\u0439, \u043f\u043e\u043a\u0430 \u043f\u0443\u0441\u0442\u043e\u0439, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f:  <\/p>\n<pre><code class=\"java\">    public void OnOpenFileClick(View view) {     } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c:  <\/p>\n<pre><code class=\"java\">import android.app.AlertDialog; import android.content.Context;  public class OpenFileDialog extends AlertDialog.Builder {      public OpenFileDialog(Context context) {         super(context);         setPositiveButton(android.R.string.ok, null)                 .setNegativeButton(android.R.string.cancel, null);     } } <\/code><\/pre>\n<p>  \u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0434\u0438\u0430\u043b\u043e\u0433:  <\/p>\n<pre><code class=\"java\">OpenFileDialog fileDialog = new OpenFileDialog(this); fileDialog.show(); <\/code><\/pre>\n<p>  \u041a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0431\u044b \u0438 \u0441\u0430\u043c\u0438 \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u0439\u0442\u0438. \u041d\u0430\u0447\u043d\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0441 \u043a\u043e\u0440\u043d\u044f <b>sdcard<\/b>, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u043e\u043b\u0435:  <\/p>\n<pre><code class=\"java\">private String currentPath = Environment.getExternalStorageDirectory().getPath(); <\/code><\/pre>\n<p>  \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434:  <\/p>\n<pre><code class=\"javascript\">    private String[] getFiles(String directoryPath){         File directory = new File(directoryPath);         File[] files = directory.listFiles();         String[] result = new String[files.length];         for (int i = 0; i &lt; files.length; i++) {             result[i] = files[i].getName();         }         return result;     }  <\/code><\/pre>\n<p>  (\u0442\u0430\u043a \u043a\u0430\u043a \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u043a \u043a\u043b\u0430\u0441\u0441\u0443 \u2013 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0443 \u043b\u044e\u0431\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0431\u0435\u0437 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u2014 \u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 <a href=\"https:\/\/code.google.com\/p\/google-collections\/\">google-collections<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0438 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e \u0441\u0442\u0430\u0440\u0438\u043d\u043a\u0435), \u0430 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a \u0432\u044b\u0437\u043e\u0432\u0443 <b>setNegativeButton<\/b> \u0434\u043e\u0431\u0430\u0432\u0438\u043c <b>.setItems(getFiles(currentPath), null)<\/b>.  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage3\/91a\/17f\/703\/91a17f7032ed216a7fc0d7cdb7936a5b.png\" \/><\/div>\n<p>  \u0427\u0442\u043e \u0436\u0435, \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u0444\u0430\u0439\u043b\u044b \u043d\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430 <b>Adapter<\/b> \u043a\u0430\u043a \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441, \u0437\u0430\u043c\u0435\u043d\u0438\u043c <b>setItems<\/b> \u043d\u0430 <b>setAdapter<\/b> \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c <b>getFiles<\/b>:   <\/p>\n<pre><code class=\"java\">private class FileAdapter extends ArrayAdapter&lt;File&gt; {          public FileAdapter(Context context, List&lt;File&gt; files) {             super(context, android.R.layout.simple_list_item_1, files);         }          @Override         public View getView(int position, View convertView, ViewGroup parent) {             TextView view = (TextView) super.getView(position, convertView, parent);             File file = getItem(position);             view.setText(file.getName());             return view;         }     } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">.setAdapter(new FileAdapter(context, getFiles(currentPath)), null) <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">    private List&lt;File&gt; getFiles(String directoryPath){         File directory = new File(directoryPath);         List&lt;File&gt; fileList = Arrays.asList(directory.listFiles());         Collections.sort(fileList, new Comparator&lt;File&gt;() {             @Override             public int compare(File file, File file2) {                 if (file.isDirectory() && file2.isFile())                     return -1;                 else if (file.isFile() && file2.isDirectory())                     return 1;                 else                     return file.getPath().compareTo(file2.getPath());             }         });         return fileList;     } <\/code><\/pre>\n<p>  \u0415\u0449\u0435 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u043e \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 \u043f\u0430\u043f\u043a\u0435 \u0438\u0434\u0442\u0438 \u0432\u043d\u0443\u0442\u0440\u044c. \u041a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e <b>listview<\/b> \u044f \u043d\u0435 \u043d\u0430\u0448\u0435\u043b, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u043b \u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c. \u041f\u043b\u044e\u0441, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f <b>adapter<\/b>\u2019\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 <b>listview<\/b> \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u043e <b>exception<\/b>, \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435:  <\/p>\n<pre><code class=\"java\">    private List&lt;File&gt; files = new ArrayList&lt;File&gt;();      public OpenFileDialog(Context context) {         super(context);         files.addAll(getFiles(currentPath));         ListView listView = createListView(context);         listView.setAdapter(new FileAdapter(context, files));         setView(listView)                 .setPositiveButton(android.R.string.ok, null)                 .setNegativeButton(android.R.string.cancel, null);     }      private void RebuildFiles(ArrayAdapter&lt;File&gt; adapter) {         files.clear();         files.addAll(getFiles(currentPath));         adapter.notifyDataSetChanged();     }      private ListView createListView(Context context) {         ListView listView = new ListView(context);         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {              @Override             public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int index, long l) {                 final ArrayAdapter&lt;File&gt; adapter = (FileAdapter) adapterView.getAdapter();                 File file = adapter.getItem(index);                 if (file.isDirectory()) {                     currentPath = file.getPath();                     RebuildFiles(adapter);                 }              }         });         return listView;     } <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0432\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0436\u0430\u0432 \u043d\u0430 \u043f\u0430\u043f\u043a\u0443 <b>Android<\/b> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0433\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 <b>data<\/b>, \u0438 \u043d\u0430\u0448\u0435 \u043e\u043a\u043d\u043e \u0442\u0443\u0442 \u0436\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0435.   <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage3\/b95\/ce0\/a38\/b95ce0a38a526eaba309238350309278.png\" \/><\/div>\n<p>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043c\u043d\u0435 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c, \u0438 \u044f \u0441\u0442\u0430\u043b \u0438\u0441\u043a\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u044e \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2013 \u044d\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 <b>setMinimumHeight<\/b>. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f <b>listview<\/b> \u0432\u044b\u0437\u0432\u0430\u043b\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043d\u043e \u043e\u043d\u0438 \u0440\u0435\u0448\u0438\u043b\u0438\u0441\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439 \u0435\u0433\u043e \u0432 <b>LinearLayout<\/b>:  <\/p>\n<pre><code class=\"java\">    public OpenFileDialog(Context context) {         super(context);         LinearLayout linearLayout = createMainLayout(context);         files.addAll(getFiles(currentPath));         ListView listView = createListView(context);         listView.setAdapter(new FileAdapter(context, files));         linearLayout.addView(listView);         setView(linearLayout)                 .setPositiveButton(android.R.string.ok, null)                 .setNegativeButton(android.R.string.cancel, null);     }      private LinearLayout createMainLayout(Context context) {         LinearLayout linearLayout = new LinearLayout(context);         linearLayout.setOrientation(LinearLayout.VERTICAL);         linearLayout.setMinimumHeight(750);         return linearLayout;     } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435 \u0442\u0430\u043a\u0438\u043c, \u043a\u0430\u043a\u0438\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b: \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0434\u0438\u0430\u043b\u043e\u0433 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442 \u043d\u0430 \u0432\u0435\u0441\u044c \u044d\u043a\u0440\u0430\u043d, \u0430 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <b>Android<\/b> \u2013 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0434\u043e <b>750px<\/b>. \u0414\u0430 \u0435\u0449\u0435 \u0438 \u044d\u043a\u0440\u0430\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u0443\u044e \u0432\u044b\u0441\u043e\u0442\u0443. \u0420\u0435\u0448\u0438\u043c \u0441\u0440\u0430\u0437\u0443 \u043e\u0431\u0435 \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 <b>setMinimumHeight<\/b> \u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0443\u044e \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430:  <\/p>\n<pre><code class=\"java\">    private static Display getDefaultDisplay(Context context) {         return ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();     }      private static Point getScreenSize(Context context) {         Point screeSize = new Point();         getDefaultDisplay(context).getSize(screeSize);         return screeSize;     }      private static int getLinearLayoutMinHeight(Context context) {         return getScreenSize(context).y;     }      private LinearLayout createMainLayout(Context context) {         LinearLayout linearLayout = new LinearLayout(context);         linearLayout.setOrientation(LinearLayout.VERTICAL);         linearLayout.setMinimumHeight(getLinearLayoutMinHeight(context));         return linearLayout;     } <\/code><\/pre>\n<p>  \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0443\u0433\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432 <b>setMinimumHeight<\/b> \u043f\u043e\u043b\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0440\u0430\u043d\u0430, \u0441\u0430\u043c\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0432 \u043a\u0430\u043a\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043e\u043d \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0432\u0432\u0435\u0440\u0445. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043f\u0435\u0440\u0432\u043e\u0439. \u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u043b\u0435\u0433\u043a\u043e \u2014 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>title<\/b> \u0432 <b>currentPath<\/b> \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438 \u0432 \u043c\u0435\u0442\u043e\u0434 <b>RebuildFiles<\/b> \u0432\u044b\u0437\u043e\u0432 <b>setTitle(currentPath)<\/b>.  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage3\/cb6\/7e6\/738\/cb67e6738a4fa7d615782f408448d014.png\" \/><\/div>\n<p>  \u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <b>Android<\/b>:  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage3\/9fe\/906\/a48\/9fe906a48e620852e5fafd2aaffaa27a.png\" \/><\/div>\n<p>  \u0410 \u043d\u0435\u0442 \u2013 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f. \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 <b>setTitle<\/b> \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430 \u0434\u0438\u0430\u043b\u043e\u0433\u0430, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u043e\u043b\u0447\u0438\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0441\u043e\u0437\u0434\u0430\u0432 \u0441\u0432\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0432 \u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439:  <\/p>\n<pre><code class=\"java\">private TextView title;  public OpenFileDialog(Context context) {         super(context);         title = createTitle(context);         LinearLayout linearLayout = createMainLayout(context);         files.addAll(getFiles(currentPath));         ListView listView = createListView(context);         listView.setAdapter(new FileAdapter(context, files));         linearLayout.addView(listView);         setCustomTitle(title)                 .setView(linearLayout)                 .setPositiveButton(android.R.string.ok, null)                 .setNegativeButton(android.R.string.cancel, null);     }      private  int getItemHeight(Context context) {         TypedValue value = new TypedValue();         DisplayMetrics metrics = new DisplayMetrics();         context.getTheme().resolveAttribute(android.R.attr.rowHeight, value, true);         getDefaultDisplay(context).getMetrics(metrics);         return (int)TypedValue.complexToDimension(value.data, metrics);     }      private TextView createTitle(Context context) {         TextView textView = new TextView(context);         textView.setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault_DialogWindowTitle);         int itemHeight = getItemHeight(context);         textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight));         textView.setMinHeight(itemHeight);         textView.setGravity(Gravity.CENTER_VERTICAL);         textView.setPadding(15, 0, 0, 0);         textView.setText(currentPath);         return textView;     }      private void RebuildFiles(ArrayAdapter&lt;File&gt; adapter) {         files.clear();         files.addAll(getFiles(currentPath));         adapter.notifyDataSetChanged();         title.setText(currentPath);     } <\/code><\/pre>\n<p>  \u0418 \u0441\u043d\u043e\u0432\u0430 \u043d\u0435 \u0432\u0441\u0435 \u043b\u0430\u0434\u043d\u043e: \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0439\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u043b\u0435\u043a\u043e, \u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0432\u043b\u0435\u0437\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage3\/231\/909\/d9c\/231909d9c533d7866ecc94b8e9392b0b.png\" \/><\/div>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 <b>setMaximumWidth<\/b> \u043d\u0435 \u0432\u0435\u0440\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438. \u041d\u0435 \u0437\u043d\u0430\u044e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u043d\u043e \u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"java\">public int getTextWidth(String text, Paint paint) {         Rect bounds = new Rect();         paint.getTextBounds(text, 0, text.length(), bounds);         return bounds.left + bounds.width() + 80;     }      private void changeTitle() {         String titleText = currentPath;         int screenWidth = getScreenSize(getContext()).x;         int maxWidth = (int) (screenWidth * 0.99);         if (getTextWidth(titleText, title.getPaint()) &gt; maxWidth) {             while (getTextWidth(&quot;...&quot; + titleText, title.getPaint()) &gt; maxWidth)             {                 int start = titleText.indexOf(&quot;\/&quot;, 2);                 if (start &gt; 0)                     titleText = titleText.substring(start);                 else                     titleText = titleText.substring(2);             }             title.setText(&quot;...&quot; + titleText);         } else {             title.setText(titleText);         }     } <\/code><\/pre>\n<p>  \u0420\u0435\u0448\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <b>LinearLayout<\/b>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d <b>TextView<\/b> \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0440\u0435\u0444\u0440\u0430\u043a\u0442\u043e\u0440\u0438\u043c \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"java\">    private ListView listView;      public OpenFileDialog(Context context) {         super(context);         title = createTitle(context);         changeTitle();         LinearLayout linearLayout = createMainLayout(context);         linearLayout.addView(createBackItem(context));         files.addAll(getFiles(currentPath));         listView = createListView(context);         listView.setAdapter(new FileAdapter(context, files));         linearLayout.addView(listView);         setCustomTitle(title)                 .setView(linearLayout)                 .setPositiveButton(android.R.string.ok, null)                 .setNegativeButton(android.R.string.cancel, null);     }       private TextView createTextView(Context context, int style) {         TextView textView = new TextView(context);         textView.setTextAppearance(context, style);         int itemHeight = getItemHeight(context);         textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight));         textView.setMinHeight(itemHeight);         textView.setGravity(Gravity.CENTER_VERTICAL);         textView.setPadding(15, 0, 0, 0);         return textView;     }      private TextView createTitle(Context context) {         TextView textView = createTextView(context, android.R.style.TextAppearance_DeviceDefault_DialogWindowTitle);         return textView;     }          private TextView createBackItem(Context context) {         TextView textView = createTextView(context, android.R.style.TextAppearance_DeviceDefault_Small);         Drawable drawable = getContext().getResources().getDrawable(android.R.drawable.ic_menu_directions);         drawable.setBounds(0, 0, 60, 60);         textView.setCompoundDrawables(drawable, null, null, null);         textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));         textView.setOnClickListener(new View.OnClickListener() {              @Override             public void onClick(View view) {                 File file = new File(currentPath);                 File parentDirectory = file.getParentFile();                 if (parentDirectory != null) {                     currentPath = parentDirectory.getPath();                     RebuildFiles(((FileAdapter) listView.getAdapter()));                 }             }         });         return textView;     }  <\/code><\/pre>\n<p>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0448\u0430\u0433 \u0432\u0432\u0435\u0440\u0445, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0435\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>RebuildFiles<\/b>:   <\/p>\n<pre><code class=\"java\">    private void RebuildFiles(ArrayAdapter&lt;File&gt; adapter) {         try{             List&lt;File&gt; fileList = getFiles(currentPath);             files.clear();             files.addAll(fileList);             adapter.notifyDataSetChanged();             changeTitle();         } catch (NullPointerException e){             Toast.makeText(getContext(), android.R.string.unknownName, Toast.LENGTH_SHORT).show();         }     } <\/code><\/pre>\n<p>  (c\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435, \u043d\u043e \u0432\u0441\u043a\u043e\u0440\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e).<br \/>  \u041d\u0438 \u043e\u0434\u0438\u043d <b>OpenFileDialog<\/b> \u043d\u0435 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0435\u0437 \u0444\u0438\u043b\u044c\u0442\u0440\u0430. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0438 \u0435\u0433\u043e:  <\/p>\n<pre><code class=\"java\">    private FilenameFilter filenameFilter;     public OpenFileDialog setFilter(final String filter) {         filenameFilter = new FilenameFilter() {              @Override             public boolean accept(File file, String fileName) {                 File tempFile = new File(String.format(&quot;%s\/%s&quot;, file.getPath(), fileName));                 if (tempFile.isFile())                     return tempFile.getName().matches(filter);                 return true;             }         };         return this;     } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">List&lt;File&gt; fileList = Arrays.asList(directory.listFiles(filenameFilter)); <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">new OpenFileDialog(this).setFilter(&quot;.*\\\\.txt&quot;); <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u2014 \u0444\u0438\u043b\u044c\u0442\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u2013 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0434\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430. \u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c \u0435\u0451 \u0432 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <b>show<\/b>:   <\/p>\n<pre><code class=\"java\">    public OpenFileDialog(Context context) {         super(context);         title = createTitle(context);         changeTitle();         LinearLayout linearLayout = createMainLayout(context);         linearLayout.addView(createBackItem(context));         listView = createListView(context);         linearLayout.addView(listView);         setCustomTitle(title)                 .setView(linearLayout)                 .setPositiveButton(android.R.string.ok, null)                 .setNegativeButton(android.R.string.cancel, null);     }      @Override     public AlertDialog show() {         files.addAll(getFiles(currentPath));         listView.setAdapter(new FileAdapter(getContext(), files));         return super.show();     } <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c: \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u043f\u043e\u043d\u044f\u043b \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c <b>CHOICE_MODE_SINGLE<\/b>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d (\u043a\u043e\u0434) \u0438 \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0435\u0437 <b>CHOICE_MODE_SINGLE<\/b>, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u043e\u0431\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u0431\u0435\u0437 \u043d\u0435\u0433\u043e:  <\/p>\n<pre><code class=\"java\">private int selectedIndex = -1; <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">        @Override         public View getView(int position, View convertView, ViewGroup parent) {             TextView view = (TextView) super.getView(position, convertView, parent);             File file = getItem(position);             view.setText(file.getName());             if (selectedIndex == position)                 view.setBackgroundColor(getContext().getResources().getColor(android.R.color.holo_blue_light));             else                 view.setBackgroundColor(getContext().getResources().getColor(android.R.color.background_dark));             return view;         } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">    private void RebuildFiles(ArrayAdapter&lt;File&gt; adapter) {         try{             List&lt;File&gt; fileList = getFiles(currentPath);             files.clear();             selectedIndex = -1;             files.addAll(fileList);             adapter.notifyDataSetChanged();             changeTitle();         } catch (NullPointerException e){             Toast.makeText(getContext(), android.R.string.unknownName, Toast.LENGTH_SHORT).show();         }     }      private ListView createListView(Context context) {         ListView listView = new ListView(context);         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {              @Override             public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int index, long l) {                 final ArrayAdapter&lt;File&gt; adapter = (FileAdapter) adapterView.getAdapter();                 File file = adapter.getItem(index);                 if (file.isDirectory()) {                     currentPath = file.getPath();                     RebuildFiles(adapter);                 } else {                     if (index != selectedIndex)                         selectedIndex = index;                     else                         selectedIndex = -1;                     adapter.notifyDataSetChanged();                 }             }         });         return listView;     } <\/code><\/pre>\n<p>  \u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f:   <\/p>\n<pre><code class=\"java\">    public interface OpenDialogListener{         public void OnSelectedFile(String fileName);     }     private OpenDialogListener listener;      public OpenFileDialog setOpenDialogListener(OpenDialogListener listener) {         this.listener = listener;         return this;     } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">\u2026 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {                     @Override                     public void onClick(DialogInterface dialog, int which) {                         if (selectedIndex &gt; -1 && listener != null) {                             listener.OnSelectedFile(listView.getItemAtPosition(selectedIndex).toString());                         }                     }                 }) \u2026 <\/code><\/pre>\n<p>  \u041d\u0443, \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432:  <\/p>\n<pre><code class=\"java\">    OpenFileDialog fileDialog = new OpenFileDialog(this)                     .setFilter(&quot;.*\\\\.csv&quot;)                     .setOpenDialogListener(new OpenFileDialog.OpenDialogListener() {                         @Override                         public void OnSelectedFile(String fileName) {                             Toast.makeText(getApplicationContext(), fileName, Toast.LENGTH_LONG).show();                         }                     });             fileDialog.show(); <\/code><\/pre>\n<p>  \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a:   <\/p>\n<pre><code class=\"java\">    private Drawable folderIcon;     private Drawable fileIcon;     private String accessDeniedMessage;     public OpenFileDialog setFolderIcon(Drawable drawable){         this.folderIcon = drawable;         return this;     }      public OpenFileDialog setFileIcon(Drawable drawable){         this.fileIcon = drawable;         return this;     }      public OpenFileDialog setAccessDeniedMessage(String message) {         this.accessDeniedMessage = message;         return this;     }      private void RebuildFiles(ArrayAdapter&lt;File&gt; adapter) {         try{             List&lt;File&gt; fileList = getFiles(currentPath);             files.clear();             selectedIndex = -1;             files.addAll(fileList);             adapter.notifyDataSetChanged();             changeTitle();         } catch (NullPointerException e){             String message = getContext().getResources().getString(android.R.string.unknownName);             if (!accessDeniedMessage.equals(&quot;&quot;))                 message = accessDeniedMessage;             Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();         }     } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">        @Override         public View getView(int position, View convertView, ViewGroup parent) {             TextView view = (TextView) super.getView(position, convertView, parent);             File file = getItem(position);             view.setText(file.getName());             if (file.isDirectory()) {                 setDrawable(view, folderIcon);             } else {                 setDrawable(view, fileIcon);                 if (selectedIndex == position)                     view.setBackgroundColor(getContext().getResources().getColor(android.R.color.holo_blue_dark));                 else                     view.setBackgroundColor(getContext().getResources().getColor(android.R.color.transparent));             }             return view;         }          private void setDrawable(TextView view, Drawable drawable) {             if (view != null){                 if (drawable != null){                     drawable.setBounds(0, 0, 60, 60);                     view.setCompoundDrawables(drawable, null, null, null);                 } else {                     view.setCompoundDrawables(null, null, null, null);                 }             }         } <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u043e\u043a\u0430 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u043c\u043e\u0433 \u0440\u0435\u0448\u0438\u0442\u044c, \u0438 \u0431\u044b\u043b \u0431\u044b \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d \u0437\u0430 \u043b\u044e\u0431\u0443\u044e \u043f\u043e\u043c\u043e\u0449\u044c:  <\/p>\n<ol>\n<li>\u041f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 \u043f\u0443\u043d\u043a\u0442 \u00ab\u0412\u0432\u0435\u0440\u0445\u00bb. \u0412\u0440\u043e\u0434\u0435 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 <b>setBackgroundResource<\/b> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <b>android.R.drawable.list_selector_background<\/b>, \u043d\u043e \u044d\u0442\u043e \u0441\u0442\u0438\u043b\u044c <b>android 2.x<\/b>, \u0430 \u043d\u0435 <b>holo<\/b>!<\/li>\n<li>\u0426\u0432\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0442\u0435\u043c\u044b.<\/li>\n<\/ol>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0441 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c \u0436\u0434\u0443 \u043b\u044e\u0431\u044b\u0445 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0439 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 <a href=\"https:\/\/github.com\/Scogun\/Android-OpenFileDialog\">\u0437\u0434\u0435\u0441\u044c<\/a>.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/203884\/\"> http:\/\/habrahabr.ru\/post\/203884\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043a\u0430\u043a \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u043e\u0434 <b>Android<\/b>, \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0434\u043d\u044f\u0445 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u044b\u0431\u043e\u0440 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0422\u0430\u043a \u043a\u0430\u043a \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432 <b>Android<\/b> \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0435\u0442, \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u043a <a href=\"https:\/\/www.google.ru\/\">\u0432\u0435\u043b\u0438\u043a\u043e\u043c\u0443 \u0438 \u0443\u0436\u0430\u0441\u043d\u043e\u043c\u0443<\/a>. \u042d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c, \u043d\u043e \u0438\u0437 \u0432\u043e\u0440\u043e\u0445\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 <a href=\"http:\/\/stackoverflow.com\/\">stackoverflow<\/a> \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u0443\u043c\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430:  <\/p>\n<ol>\n<li> <a href=\"https:\/\/code.google.com\/p\/android-file-dialog\/\">Android File Dialog<\/a> \u2013 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 stackoverflow \u0432\u0435\u0434\u0443\u0442 \u0441\u044e\u0434\u0430. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e <b>activity<\/b>, \u0430 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0447\u0435\u0433\u043e-\u0442\u043e \u0432 \u0434\u0443\u0445\u0435 <b>OpenFileDialog<\/b>\u2019\u0430 \u0438\u0437 <b>.Net<\/b>.<\/li>\n<li>\u0412 <a href=\"http:\/\/habrahabr.ru\/post\/109486\/\">\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u0431 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0430\u0439\u043b-\u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0435, \u0438 \u043f\u043e\u0447\u0435\u0440\u043f\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u0434\u0435\u0438 \u0438\u0437 \u043d\u0435\u0451 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c.<\/li>\n<li>\u0418\u0434\u0435\u044f \u0436\u0435 <a href=\"http:\/\/www.wtg.ru\/products\/onlinedev\/031\/\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c, \u043e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435.<\/li>\n<\/ol>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043d\u0430\u0447\u0430\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u0410 \u043f\u043e\u0441\u0435\u043c\u0443, \u0440\u0435\u0448\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0430 \u0432\u0441\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u0432\u0435\u043b\u0438. \u0416\u0435\u043b\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0439\u0442\u0438 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u2013 <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-203884","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203884"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203884\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}