Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:52:26+00:00 2026-05-28T00:52:26+00:00

Can I use OpenFileDialog in Android? I want to choose image from OpenFileDialog and

  • 0

Can I use OpenFileDialog in Android? I want to choose image from OpenFileDialog and save image to a SQLite database and resource folder. How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:52:27+00:00Added an answer on May 28, 2026 at 12:52 am

    This link helped me

    I have created FolderLayout which may help you.

    folderview.xml

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView android:id="@+id/path" android:text="Path"
            android:layout_width="match_parent" android:layout_height="wrap_content"></TextView>
        <ListView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/list"></ListView>
    
    </LinearLayout>
    

    FolderLayout.java

    package com.testsample.activity;
    
    
    
    
       public class FolderLayout extends LinearLayout implements OnItemClickListener {
    
        Context context;
        IFolderItemListener folderListener;
        private List<String> item = null;
        private List<String> path = null;
        private String root = "/";
        private TextView myPath;
        private ListView lstView;
    
        public FolderLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            // TODO Auto-generated constructor stub
            this.context = context;
    
    
            LayoutInflater layoutInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.folderview, this);
    
            myPath = (TextView) findViewById(R.id.path);
            lstView = (ListView) findViewById(R.id.list);
    
            Log.i("FolderView", "Constructed");
            getDir(root, lstView);
    
        }
    
        public void setIFolderItemListener(IFolderItemListener folderItemListener) {
            this.folderListener = folderItemListener;
        }
    
        //Set Directory for view at anytime
        public void setDir(String dirPath){
            getDir(dirPath, lstView);
        }
    
    
        private void getDir(String dirPath, ListView v) {
    
            myPath.setText("Location: " + dirPath);
            item = new ArrayList<String>();
            path = new ArrayList<String>();
            File f = new File(dirPath);
            File[] files = f.listFiles();
    
            if (!dirPath.equals(root)) {
    
                item.add(root);
                path.add(root);
                item.add("../");
                path.add(f.getParent());
    
            }
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                path.add(file.getPath());
                if (file.isDirectory())
                    item.add(file.getName() + "/");
                else
                    item.add(file.getName());
    
            }
    
            Log.i("Folders", files.length + "");
    
            setItemList(item);
    
        }
    
        //can manually set Item to display, if u want
        public void setItemList(List<String> item){
            ArrayAdapter<String> fileList = new ArrayAdapter<String>(context,
                    R.layout.row, item);
    
            lstView.setAdapter(fileList);
            lstView.setOnItemClickListener(this);
        }
    
    
        public void onListItemClick(ListView l, View v, int position, long id) {
            File file = new File(path.get(position));
            if (file.isDirectory()) {
                if (file.canRead())
                    getDir(path.get(position), l);
                else {
    //what to do when folder is unreadable
                    if (folderListener != null) {
                        folderListener.OnCannotFileRead(file);
    
                    }
    
                }
            } else {
    
    //what to do when file is clicked
    //You can add more,like checking extension,and performing separate actions
                if (folderListener != null) {
                    folderListener.OnFileClicked(file);
                }
    
            }
        }
    
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            onListItemClick((ListView) arg0, arg0, arg2, arg3);
        }
    
    }
    

    And an Interface IFolderItemListener to add what to do when a fileItem is clicked

    IFolderItemListener.java

    public interface IFolderItemListener {
    
        void OnCannotFileRead(File file);//implement what to do folder is Unreadable
        void OnFileClicked(File file);//What to do When a file is clicked
    }
    

    Also an xml to define the row

    row.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rowtext" android:layout_width="fill_parent"
        android:textSize="23sp" android:layout_height="match_parent"/>
    

    How to Use in your Application

    In your xml,

    folders.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:orientation="horizontal" android:weightSum="1">
        <com.testsample.activity.FolderLayout android:layout_height="match_parent" layout="@layout/folderview"
            android:layout_weight="0.35"
            android:layout_width="200dp" android:id="@+id/localfolders"></com.testsample.activity.FolderLayout></LinearLayout>
    

    In Your Activity,

    SampleFolderActivity.java

    public class SampleFolderActivity extends Activity implements IFolderItemListener {
    
        FolderLayout localFolders;
    
        /** Called when the activity is first created. */
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            localFolders = (FolderLayout)findViewById(R.id.localfolders);
            localFolders.setIFolderItemListener(this);
                localFolders.setDir("./sys");//change directory if u want,default is root   
    
        }
    
        //Your stuff here for Cannot open Folder
        public void OnCannotFileRead(File file) {
            // TODO Auto-generated method stub
            new AlertDialog.Builder(this)
            .setIcon(R.drawable.icon)
            .setTitle(
                    "[" + file.getName()
                            + "] folder can't be read!")
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
    
                        public void onClick(DialogInterface dialog,
                                int which) {
    
    
                        }
                    }).show();
    
        }
    
    
        //Your stuff here for file Click
        public void OnFileClicked(File file) {
            // TODO Auto-generated method stub
            new AlertDialog.Builder(this)
            .setIcon(R.drawable.icon)
            .setTitle("[" + file.getName() + "]")
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
    
    
                        }
    
                    }).show();
        }
    
    }
    

    Import the libraries needed. Hope these help you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use openfiledialog and a picturebox and upload an image and store
You can use SelectFolder() to get a folder or GetOpenFolderitem(filter as string) to get
I can use VS08's MFC/ActiveX template to create a C++ ActiveX object that I
I can't use OpenFileDialog in my application. As an alternative I use GetOpenFileName() method:
I have written a custom dialog (form) that I can use in a C#
I am trying to use an OpenFileDialouge control to select a folder, so that
We can use the following syntax to initialize a vector. // assume that UserType
I can use os.times or resource.getrlimit to get user time of the current process,
Is it possible to use the OpenFileDialog class select a file OR folder? It
Can I use self = nil in an instance method so that when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.