How to create buttons dynamicly based on file/folder structure in android - android

im new to android and im trying to make a "simple" app.
However i would like to know if, what i have planned, is possible in android.
Basicly it's a crude database reader/navigator.
I made a folder structure in the assets folder with a few directories and *.txt files.
Now the plan is to read/scan the folder structure on startup of the program and dynamicly create buttons labeld based on the folder,- and file names.
The buttons have to link to the files and folders so the user can navigate the folder structure and open a *.txt file and read it. Also the idea is that the buttons reflect the folder structure as it is in the assets folder.
The idea is that the user can easly retrieve info from the app and i can add info to the app trough *.txt files and adjust the structure just by adding/removing directories and files in the assets folder.
i am using android studio but like i already say'd: i am a beginner with programming and would like to know if this is even possible with android.
And if it is: could someone please tell me how i should start this project or link me to some example code on how this could be done?
Thanks in advance.

If i read your idea correctly, what you are trying to achieve is very much possible. I would start looking at the AssetManager class and I believe what you are looking for is the list() command which should give you what you need.
https://developer.android.com/reference/android/content/res/AssetManager.html
You can obtain the AssetManager from everywhere within your app through the Context object which you will find to be everywhere around. ;)
From there on you can build your hierarchy and open files.
There are some useful wizard projects in Android studio, which will basically setup a general structure of an Android App. I would recommend starting with a Single Activity application and move on from there.

It sounds like ListView is something that could be beneficial for you here. ListView allows you to dynamically create buttons, or whatever you need. ListView has the added advantage that you can use an XML file to inform the ListView of how to display the buttons, images or whatever you want to display for each element of the list. There are loads of videos demonstrating how to use ListView, but here is a link to its documentation: https://developer.android.com/guide/topics/ui/layout/listview.html
Also, if you'd like a structured way of learning how to develop apps, I'd recommend the Android courses on Udacity to help you out.
Best of luck!

Related

How to implement file explorer for Android without ListView

I'm going to develop my file explorer on Android.
On the most examples and tutorials it is done via ListView.
And my question is:
Is it possible to view files without ListView? May be there are more professional ways to do that.
My file explorer should be simple but fully functional. The features are scrolling, context menu, multi selection support...
Thank you very much.
You can do it any way you want without using ListView:
You can set up a grid layout and have tiles of icons representing directories and files
You can make it look like Linux terminal and print everything with simple text
You can make a 3D environment like in hacker movies from early 90s and visualize your file system as a futuristic city
You can create a SurfaceView, or an ImageView and draw everything on it using Canvas
etc.

Updating XML file on Android

I am fairly new at developing for Android and was hoping to get some help with something.
First, just a brief idea of what I am trying to achieve.
Within the app I am developing, the user can create a project profile for each new project he starts. I have already created the code to create a new XML file for each new project which is stored on the SD Card.
Now I want to create a list of the various projects on the main screen for the user to select from, but I'm not 100% sure how to go about this. My first thought was to have an XML file called Projects List which lists all the projects that have been created. But I just can't seem to figure out a way to update an XML file every time a new project is created, and this is where I was looking for some help.
Can someone please help me to understand how to update an XML file?
Thanks in advance for any replies.
My first thought was to have an XML file called Projects List which
lists all the projects that have been created.
Instead of doing this, why not simply see how many xml files there were created(corresponding to projects created)? I assume that, now, you're saving those project in a folder created by you on the SD Card so when it's time to show that information to the user simple check your projects folder, see how many there are(get the names, get a reference to those xml files so you could open them on a user action etc) and present them to the user.
This would be a lot simpler then implementing the logic to update a xml each time the user does some changes to the projects, not to mention the case when the user might delete those xml files when your app is not running.
I would do the following.
The user create some projects - and for each project you have an xml file.
You check for all xml files - grab a bit of info from each, and build a ListView :
Android listview example
From here you can create a custom adapter which would do the hard work of working out what information you need from each XML file and then when the user clicks the 'browse projects button' they can see all projects in a listview?

organizing android apps in eclipse

I have an app on the iPhone and need to port it to android. For this I would like to group screen related files like classes and xml per screen in one "screen group" per screen somehow, ideally also strings and other value files
if I use folders I can only group res files separately and src files separately.
what would be the best way?
Thanks very much!
EDIT:
If that should not be possible, how to best then solve this issue? Do you create a subfolder in the src and another in the res for each screen?
The way you group files for the iphone is not possible for an android project. Android has pre determined folders which hold specific files, if you break this structure, your building process will fail. Its not ideal but that just how it it.
When it comes to source java files, they follow the concept of packages which are basically folders. The 'src' folder is the part where you can create sub folders as you desire. If you are adamant about keeping the files related to a screen in one place, you should create the layouts with java code and not use layout xml files.
But using xml layout files make development much easier and faster. Consider that as the presentation and java files as the logic+data. So group java files as you want and leave xml files in the layout folder with easy to identify names.
android uses certain directory layout for project structures (i.e. convention over configuration). Basically you will want to put your XML layout files in res/layout directory. Please read http://developer.android.com/guide/developing/projects/index.html#ApplicationProjects for further information.
Unfortunately, there's no easy way to do this in Eclipse. You can't create custom directories in your Android app's /res directory, you can only use permitted dir-names. E.g. you can't have a /res/layout-myscreen1 and /res/layout-myscreen2. You also must put your resources in /res, and your code files in packages, so they're at separate places in your project.
You can use Working Sets to group related files together however, but they're quite painful to use IMHO. Check the eclipse docs and tutorials out on them.

Creating a project to be reused

I'm sure you can help such a newbie like I am.
I created a project in android and I want to use it as a model for next 10 and more apps, just changing the raw sources.
I mean I want to make some products i.e. 10 videocharts about norway, I make one project with the needed activity and resources so each app will differ only for the content value.
I will keep of course the same file name too if needed.
How can I save the project?
Cause I tried to make a new project from resource but I get an error on top of the tab saying Manifest is not present in the folder while manifest is actually there, and I cannot proceed further.
Thank you
ANgelo
This sounds like a place to use an Android library project.

NetBeans and Android image

New to Android development and have decided to use NetBeans 6.9.1 as my IDE. So far the process has been somewhat painful, but I'm getting things rolling. However, I am creating an ImageView subclass for my first custom View and I can't figure out how to add my Box.png file to the project. Drag and Drop doesn't work, there are no right-click options to add a file to the Resources folder, no dropdown menus to add images, no way to add the image to a package. Could use some insight, thanks!
Just go to the project folder and copy the images you want into the res/drawable folder. The IDE helps you a lot with code completion, error checking, etc... but that simple task can be done by hand.
Then, you can reference your resources by using something like: R.drawable.image Notice that I'm not using the image extension. If you wonder what R is, let me give you a brief explanation:
Each resource that is saved in the resources directory is referenced in the R class. That's a file that is autogenerated by Android and it's used to reference those resources from your code. In this case, it will be in R.drawable.* since it's a drawable resource. There are other kind of resources, like layouts: R.layout.something or strings R.string.whatever. That's essential for the android development, so you better read some tutorials (or buy books) in order for you to get started.
So, in your case will be something like setImageDrawable(R.layout.wood); However, I highly recommend to read first a couple of tutorials. Google about it, you will find tons of them.

Categories

Resources