create new folder android This is a topic that many people are looking for. accountabilitynowpac.com is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, accountabilitynowpac.com would like to introduce to you How to Code the Creation of a New Folder for Your Android File Manager App in Android Studio. Following along are instructions in the video below:
“And welcome to this new android development tutorial in this tutorial. We will go on on part 7 of how to make file manager application. Okay so previously. We did lot of cool stuff.
So i will run the app. Right now just to see where we are so we are able to list the files. We were able to use to know the directory. We are browsing right now at the top as you can see this is the download.
We can have some files here so before starting the project. Please make sure you have some files under the download folder of your device. So. I have downloaded a couple of images from the internet.
Right here it doesn t really matter the file type you are using just maybe more than five files would be okay okay so we have very cool stuff right here. But there s still some pictures that are missing for example. The ability to create a new folder. So we don t have that button here and since the bottom bar appears when we want click and we can use the delete button as you know we won t use the bottom bar.
We will use a button on the top maybe on the same bar of the download of the title in this case download okay to do that we will go to our under the studio layout. 1. That xml file and we will search for the textview that shows the path output. So the first textview okay.
What we will do here is we will create a linear layout that will enable us to have more than one element in a row. So we go and open type linear layout. Which will be much parent right. We ll be i think rap content will be okay.
Yeah. I would set it to wrap content or maybe. We have to have a little bit more height right. Here.
Maybe. Let s start with 50. Dp. Okay.
Height will be 50 dp and the orientation will be horizontal. Okay and we will get the text to that it s below that linear layout and we ll move it inside the linear layout. Okay right now we have linear layout right here and on the right of it so throughout the text view definition. We will create a button so button the width of the button will be 0.
Dp. The height of the button will be much parent and the weight of the bottom will be 1. Okay. So we have a button right here.
And we have it also the teapot okay. This is great okay so now we have to of course change the width of our text view of the pad output. We will have to set the width to 0. Dp and we have to have a weight the weight of these will be i will set it to 4.
Okay okay this button is the d button that will enables us to create a new folder. So the ib of peas will be new folder. Okay and text of this button will be an f. Which will represent a new folder.
Okay so that s that s great. We will run the app. And see how it looks okay we re compiling and running okay. We wait for the app to be compiled.
And we can see if the ui changes that we made actually apply it to the app itself. So the app is now running and as you can see here we have an n f right..
Here okay. And why the download thing is kind of has less height on these well we have to check that so the height of these will have to be changed from wrap content. Too much forint. Okay and now if you run the app.
Again. You will see that the download will be the same size as the button. Okay. So.
The water has a couple of march in some a bit of margin. So that s why it looks smaller. But it s actually the same size you can see. Andy priv e.
Okay. So now we have our new folder button. And we will leave it. As it is for now.
We will take care of that a little bit later we can later at night connie. We want. But for now. It will be an f will mean new folder.
Now we have to get that button from our java file. So we go to i will close this menu. Okay so we ll go to on the own resume it out and on the bottom of it just before the flag initializes set to true we will type final button. This will be create new older okay and we will assign it to find view by iep are divided.
E. New folder. Okay and we go. And say it little.
The click listener. So. We go. And say create new folder that set onclicklistener new onclicklistener and inside these unclick listener.
We will actually create da the folder. So how can we create the folder. So if we think we have to ask the user a name for the new folder. So we will create an alert dialog.
So we can say final alert dialog that builder and we will call it folder our new folder dialog new folder dialog okay and i will assign these two new alert tile of that builder inside is we will pass these so in this case we have to i will create a new line in order for you to see what i m doing better okay here we will pass main activity that t s okay. This is the context great so next. We will set the title of the dialog in this case. We go say new folder dialog that set title and inside here.
We will type new folder. Which will be the title for our dialog and we have to create a text box that will enable the user to input a new name for the newly created folder for that we will create an edit text which is a widget that enables us to get text input from user so edit text and i call it we have to import of course you don t have it so edit text input and i will we will initialize it to new add a text and we ll pass these or mainactivity that this actually main activity that is okay great so right now we will specify the kind of input. We want to receive so to do that we go input that set input input type and the type we will be receiving is input type that type class text because we were received text. Okay and maybe if we want to we will leave these right there and now we will set the edited text to the dialogue.
Okay. And we go. And say folder dialog new folder. Dialog that set view.
And we will pass the parameter as parameter. The newly input. We created so it passed input okay now we have to define the positive button for that we go and say new folder dialog dot set positive button and inside these we will go and say does the positive party. We can say create or create new folder or okay.
We can go and say it may be okay would be fine for this purpose. Okay and we will pass in next parameter right here..
Don t forget to to close these line to end the line with a semicolon. Okay okay so it will say okay. It s a positive button and then we have to create a click listener. So we go.
And say new dialogue interface that onclicklistener and inside the unclick. We will create a new file. In this case. For example final file new folder.
Okay and we will initialize this to new file. And this parameter. We will pass the current path so what was the current path in this case is downloads. But we need to to get the actual variable of the path and is dear director.
Which is it s not its root path root path. So that s what the variable. We are looking for okay so we go back and now we know the path. We re looking for is called root path.
So a new file. We go and pass the root path and we will concatenate new a new file separator like this and we will also get the name of the folder. The user just entered so to do that we go. And say input that get text okay so in this way we create this folder now we go and we have to check.
If the folder doesn t exist okay for that we go. And say. If you folder doesn t exist. So.
The. D folder. Doesn t exist. We go.
And say. New folder that m. kay. Dear.
Okay. Which is basically create this folder. If it doesn t exist. But now we have to here we have to update the current.
I mean we have to update. What is shown on the list view to update. What is shown on the list view. We will create sort of meets old or something okay so we go and we basically do the same with it here as you can see files is equal to peer list files files found count files that length and all of these we will come to it later.
We can optimize this okay okay so we will copy that and we will paste it after we created the new folder. Okay so now we will run the app and check that everything is working fine. And if not we will fix the box okay so off. I m compiling the app and rit running and now it s running here and if we click on the nf button at the top which means new folder we click on that and nothing happens why nothing happens because we were not showing the dialog yet okay okay we need to do a bit more stuff right here.
We also didn t set up the the negative button. So we always have to set up both buttons. So okay okay okay. So this is that positive button and before and after these.
We gotta. Say new folder dialog that set negative button and we will say cancel if we want to cancel the operation and we don t want to create the new folder. So we re gonna go say a new dialog of course. Always end the line with semi coma.
New dialog interface that unclick listener and when this is clicked. We will just say dialog that cancel or demi s business..
Whatever okay and after these we have to show the dialog for that we go. And say folder dialog new folder dialog that show and now. We can actually run the aptus check. If everything works fine.
Okay now we press on the nf and we have new folder and we can type here the name of our new folder for example. I will type my new folder. Okay and i will press. Ok.
And as you can see. Here. We have my new folder newly created right here okay. Which is great right okay.
So now. We have created a new folder. What else we have to do well of course. We can also improve how the code is being written right here because we can do lots of stuff to order everything.
We ve done so far so instead of off of calling all of these we called when we made when we want the listview to be refreshed. We should create a metal that does this for us. We can either create a meat out or we can either update. The the current directory.
Which is actually cool and useful to do ok so it will also enable us to test the app. Maybe we won t use that much that feature. When we actually are ready to cheat or to publish it up at the test. It it will be awesome ok so we go to our xml file and under the first linear layout.
We have which we created that contains the the current path output and the new folder button so before that output. We will create a new button so to make it faster. I will just copy these new folder button copy and i will double e duplicate it right here. But of course.
I will change the id to something like refresh refresh. As simple. As that ok. And as this text.
It will contain for example refresh maybe. It s ok i think or just r maybe i will just leave it as r right reload update refresh we replicate maybe ok so this is the button we create and we have two buttons a bit more symmetrical layout okay right now we have that and we will go to the first before before everything actually not really everything but before the listview setting long click. Listener there we will create the button okay. So here we will go and say final button.
Refresh button and we will set that to find view by ip arted id that refresh okay and then we go and say refresh button that set on click listener and we ll type new on click listener okay and when we click on this button be the file manager directory. And what it up what if this place to the screen will be refreshed. So we are refreshing kind of manually. If you want to tell that way a couple of times right here for example.
We are doing that here for example all these lines of code are just to refresh department. Okay. Alright are just to refresh so i will move this to the refresh me tote and here i will say i will simulate a key press on the refresh button so we re gonna say refresh button that call on click okay and we go to the refresh button and we will paste this which basically saying okay update be files list with new files list. Updated files found count new files count and here is says.
Clear the current file list and add new ones basically. The path ok and update. What s showing to the screen. Which is the adapter ok.
So that s that s great now we can do the same on the new folder. So we can make the code more elegant right here so we go to new folder. We just created a couple of minutes ago and we will delete all these lines because we can now replace all those lines with refresh button that on click call. Unclick call unclick ok.
So this is way more elegant than previously and where last lines of code. Now we will run the app to check everything..
Works fine ok. And for example. It will create a new folder again folder to for example. We ve.
Pressing ok and now. We have folder 2. Right here. Ok.
So it s now created right there and works fine. Now what happens. If we want if we imagine you close this up ok. Imagine you close this up open.
Another file manager and delete. One of these files right here. So when we open pack. These up again.
The file will still be here. Because the contents are not being updated ok to fix that we have to update the content on the on resume meet oath ok so we go to our own resume each other which is kind of large. We can make them a little bit smaller later. But ok bear with me so we go after this big bracket.
We have here of is file manager initialized. Okay. If the file manager is not initialized. We will initialize it and show all the stuff.
But in the case of a pause and resume of the activity. It will be initialized actually so in this case. We re gonna say else and here we have to access this kind of inner update thing how do we do it because we don t have access it from here i will show you so we wouldn t have access to refresh button or anything like that so we can create a refresh button as a global variable okay so we gonna say and find our refresh button which is right here and we will create it as a global variable okay so we delete the finaland button and we go outside the unrest emitter and type private button. Refresh button and now because the file manager is initialized so this means the refresh button should also be initialized that means we can access it from here so we can say refresh button that call on click and now if you run the app again we will find that we can now close the app without any problem.
And if we go back to the app. We will and we will be updating these automatically ok. So yes so this is for this video. I hope you enjoy it and i see you in the next one bye.
Thank you very much for finishing this tutorial. What you ve watched is a part of the full course named code an android file manager and explorer app. You can get the link in the description. You can also just go to youth ena and buy it the very best value is if you want this entire course.
And you re learning to be an android or ios developer. You can see this course has something like twelve videos in it but you can get the entire android mobile app developer bundle for life you can get this one bundle for 48 this is linked in the description also the idea with this bundle is you buy this bundle once and all the courses. We add for life are included in it currently there s 25 plus hours of videos from 2019. I imagine over the next eight months.
We will add 75 plus more hours. We have multiple developers working almost every day to film new videos for you to give you an outstanding experience and one place you can go to go from a total beginner to having an outstanding career as a developer online thank you for watching this with us we appreciate the chance to share educational content with you for free every day that we hope is helpful and you buying the bundle or the course helps us to pay the developers to give you even more wow. While i m asking you to do all these things i might as well just keep asking things see how many of you go for write. So let s ask you now will you please follow on twitter.
Because i think you ll love it getting to see everything at one place on jerry banfieldcom. I ve got tons of blog. Post books and youtube videos and you can see all of those gaming. Everything will be right in your twitter feed so that when you follow me there s me so much stuff.
You won t even hardly be able to see anything else i mean you re gonna absolutely love following me on twitter so join up me over on twitter and facebook and youtube and on my website. ” ..
Thank you for watching all the articles on the topic How to Code the Creation of a New Folder for Your Android File Manager App in Android Studio. All shares of accountabilitynowpac.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.