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 9176099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:01:34+00:00 2026-06-17T17:01:34+00:00

I am trying to display all layout programmatically actually i can do it in

  • 0

I am trying to display all layout programmatically
actually i can do it in pure java but not in android

here is my first class:

public DiskFileExplorer(String path, Boolean subFolder) {
    super();
    this.initialpath = path;
    this.recursivePath = subFolder;
}

public String[] list() {
    return this.listDirectory(this.initialpath);
}

@SuppressWarnings("null")
private String [] listDirectory(String dir) {
    String[] values = null;
    File file = new File(dir);
    File[] files = file.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory() == true) {
                //Log.v("Dossier" , files[i].getAbsolutePath());
                this.dircount++;
            } 
            else {
                //Log.v("Fichier" ,files[i].getName());
                values[i] = files[i].getName();
                this.filecount++;
            }
            if (files[i].isDirectory() == true && this.recursivePath == true) {
                this.listDirectory(files[i].getAbsolutePath());
            }
        }
    }
    return values;
}

and the second one:

public class MainActivity extends Activity {
    public String []DiskFileExplorer(String path, Boolean subFolder){
        return null;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView listView = (ListView) findViewById(R.id.mylist);
        String pathToExplore = "./res/layout";
        DiskFileExplorer d_expl = new DiskFileExplorer(pathToExplore,true);
        String[] values = d_expl.list();
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);
        listView.setAdapter(adapter); 
    }
}

and my 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="vertical" >

    <ListView
        android:id="@+id/mylist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout> 

and eveentually the pure java class that can do what i want to do in android:

import java.io.File;

/**
 * Lister le contenu d'un répertoire
 * @author fobec 2010
 */
public class DiskFileExplorer {

    private String initialpath = " ";
    private Boolean recursivePath = false;
    public int filecount = 0;
    public int dircount = 0;

   /**
    * Constructeur
    * @param path chemin du répertoire
    * @param subFolder analyse des sous dossiers
    */
    public DiskFileExplorer(String path, Boolean subFolder) {
        super();
        this.initialpath = path;
        this.recursivePath = subFolder;
    }

    public void list() {
        this.listDirectory(this.initialpath);
    }

    private  void listDirectory(String dir) {
        File file = new File(dir);
        File[] files = file.listFiles();

        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory() == true) {
                    System.out.println("Dossier" + files[i].getAbsolutePath());
                    this.dircount++;
                } else {
                    System.out.println("" + files[i].getName());

                    this.filecount++;
                }
                if (files[i].isDirectory() == true && this.recursivePath == true) {
                    this.listDirectory(files[i].getAbsolutePath());
                }
            }
        }
    }

    /**
     * Exemple : lister les fichiers dans tous les sous-dossiers
     * @param args
     */
    public static void main(String[] args) {
        String pathToExplore = "C:/Users/R_nkusi/workspace/Copy of AppList_bis/res/layout";
        DiskFileExplorer diskFileExplorer = new DiskFileExplorer(pathToExplore, true);
        Long start = System.currentTimeMillis();

        diskFileExplorer.list();

        System.out.println("----------");
        System.out.println("Analyse de " + pathToExplore + " en " + (System.currentTimeMillis() - start) + " mses");
        System.out.println(diskFileExplorer.dircount + " dossiers");
        System.out.println(diskFileExplorer.filecount + " fichiers");
    }
}

You have to change of course the”pathToExplore” and give one that exists in your own computer.

Thanks for the help.

  • 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-06-17T17:01:34+00:00Added an answer on June 17, 2026 at 5:01 pm

    You can read out your own XML layout files, but you cant find it in your filesystem, because it’s all compiled, thus not human readable.

    Get all layout resource id’s and their actual names:

    void getIds() {
        Field[] ID_Fields = R.layout.class.getFields();
        int[] resArray = new int[ID_Fields.length];
        for(int i = 0; i < ID_Fields.length; i++)
            try {
                resArray[i] = ID_Fields[i].getInt(null);
                System.out.println(resArray[i] + " : " + getResources().getResourceEntryName(resArray[i]));
                getEventsFromAnXML(getResources().getXml(resArray[i])); //I'll show this later
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
    }
    

    However, you need to parse the XML yourself. Here’s a small example:

    private String getEventsFromAnXML(XmlResourceParser xpp) throws XmlPullParserException, IOException {
        StringBuffer stringBuffer = new StringBuffer();
        xpp.next();
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if(eventType == XmlPullParser.START_DOCUMENT) {
                stringBuffer.append("--- Start XML ---");
            }
            else if(eventType == XmlPullParser.START_TAG) {
                stringBuffer.append("\nSTART_TAG: "+xpp.getName());
            }
            else if(eventType == XmlPullParser.END_TAG) {
                stringBuffer.append("\nEND_TAG: "+xpp.getName());
            }
            else if(eventType == XmlPullParser.TEXT) {
                stringBuffer.append("\nTEXT: "+xpp.getText());
            }
            eventType = xpp.next();
        }
        stringBuffer.append("\n--- End XML ---");
        System.out.println(stringBuffer.toString());
        return stringBuffer.toString();
    }
    

    I hope these pieces of code will help you get to where you want.

    new AlertDialog.Builder(this)
    .setTitle("Seen?")
    .setMessage("Some message.")
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // ok
        }
     })
    .setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // no
        }
     })
     .show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get all the images with class front and display their
I am trying to display all running apps on my android in a list
I'm trying to display the CalendarView in an Alert Dialog, but all that shows
I am trying to layout the content for a popup dialog box, but not
I'm trying to display all the 'legs' for each of my 'trips' in my
I am trying to display all possible values for a sub-property. Below I am
I'm trying to display all the mailboxes and their sizes for all our users
i am trying to Display all installed application and their icons. After clicking on
From any specific Post, I am trying to display all images, with their corresponding
I'm trying to loop through a list of results from MySQL and display all

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.