Prev Page Coding A Weighted Fragment
This Tutorial App Coding a Listview Fragment
Next App Tutorial Coding a Tabbed Fragment
Coding a ListView Fragment
If you are just arriving at this page; and you are not familiar with with creating Android Apps, we suggest you begin with our tutorials:
Coding Android App Pages
and How To Create a Simple App in Android
From there follow along with each tutorial lesson.
AIDE and ANDROID STUDIO
We are using AIDE(programming language java/xml), to create these tutorial apps on our
tablet(7" screen) that has android version 5.0.
Once we build and RUN our app; we then install the app on this same tablet; and the app is also installed on a smartphone that has android version 6.
current version of android is 8 with api 27.
AIDE has a free and paid version. As of this year, the paid version of AIDE is about $20 canadian.
Once you create your apps code pages, you need to RUN the app to INSTALL it on your tablet or smartphone.
can also create; RUN your apps using the code in these tutorials, with Android Studio. Android Studio is for desktop computers. Choose Java XML as the programming language.
Android Studio is free to install and use for your android app development. Although not as convenient as testing your app on an actual android device; you can test
your newly created app in Android Studio using an android emulator.
Complete Example Codes are available for each of our tutorials. With these example codes you can make a functioning android app in
either AIDE or Android Studio.
First, create a java/xml android template app using AIDE, (or Android Studio). Then you can get the code for this app from the EXAMPLE CODE section on this page.
Replace the code on the pages you need to(with our tutorial code); in order to create this app.
Sometimes, new pages have to be created.
All the other coded pages in your app
can remain as they are; they don't need to be changed.
This is the App - fragmentsWithListView
It has two fragments, and each fragment is given equal weight in the layout. To each fragment we add our list of items; for this app example;
it is English to Japanese words. The first fragment contains the list of English words; and the second fragment contains the list of Japanese spelling of the English word.
Where - How To Use Fragments
As you read in our previous tutorial; fragments are ideal to modulize your apps interface design. They are very much like an activity or textview in your app;
however they do not need to be declared in the androidmanifest.xml file; because, for coding purposes; they are considered as included in the activity.
As we learned in previous tutorials; each app's activity file you create; like; MainActivity.java, must be declared in the manifest file.
If your app has one layout (app page) named main.xml; you can add within that one activity, as many fragments as you like.
Each fragment added to your app; must be declared in the layout xml file(like main.xml), have its own xml file(like fragment1.xml), and have a java class file also(like Fragment1.java).
For example; you create a fragment named fragment1.xml; you must also create a java class page; and name it as you want. Lets say you
named it Fragment1.java(the first letter
is capped in java files).
Why do you need the java class page? Because that is where we define the fragment layout file(the fragment1.xml page). If we didn't code the java page and define
its location; then the android system wouldn't be able to locate and display the fragment1.xml page.
When creating your app,(from left menu) choose:
Create New Project;
New Android App(gradle, android Java/xml)
Hello World App Java/xml
if your using the original version of AIDE
You can name your app whatever you like; if your using the name as shown in our example code use;
for the App Name and,
for the package name(next line) use:
If you want to name it differently, you can, just change the code to whatever name you choose where it says, com.aac.learnfragments, in the coded pages, usually at the
top of the java class pages like; MainActivity.java
The Coded Pages
Code for the app - fragmentsWithListView
For this app you will use these coded pages:
1 layout file, main.xml, where you define your 2 fragments; located at res/layout/,
2 fragments, you must create 2 xml pages, one for each fragment; and put them at res/layout/fragment1.xml; and res/layout/fragment2.xml,
2 fragment java pages, you must create 2 java pages; one for each fragment; where you define the java class code for each fragment; put them at src/java/Fragment1.java and src/java/Fragment2.java
1 strings.xml page, where you define the app name fragmentsWithListView, located at res/values/strings.xml.
1 manifest xml page, where we define our app's activity java page(and other things); however, since we are not adding any new activities to our app; we don't need to define any new java pages in the
manifest file; so we can leave it as it is. As for the fragments we are adding; fragments do not need to be defined in the manifest.
Since this app has no images; we don't have to add any to our drawable-hdpi folder.
The folder src/res/drawable-hdpi also has our ic_launcher.png image; but we don't need to add it because it was
added automatically when we created our android template app.
EXAMPLE CODE - Code For This Tutorial
JUST USE YOUR MOUSE to copy the code for this tutorial
App Name is 'fragmentsWithListView - located at AppProjects/fragmentsWithListView in AIDE, open the AIDE app, then open App Projects, THEN select the 'fragmentsWithListView',
app from your files hierachy(left menu); then click on any file from the app, like strings.xml Make sure at top of page, the app name 'fragmentsWithListView' is there next to
AppProjects like so: AppProjects/fragmentWithListView, then you know you have the proper App.
Once a file is in the editor, you can edit, save it, then RUN your APP, Install,
and Open your app.
Make sure you SAVED EACH PAGE,(or choose automatic saving in AIDE settings) before you RUN your code. SAVE, RUN, INSTALL, OPEN, your App. Once it has been
installed on your tablet, you can open it Simply by Clicking on the Android little green App Icon,with the wording 'fragmensWithListView' on your tablet. It will
be with your other installed apps.
If you make further changes to this App, you need to SAVE, RUN, UPDATE, INSTALL, OPEN the app.
This free script provided by
for creating Android Apps on your tablet or cell phone(android).
Free and Paid - with Free, create java/xml android template apps, and there is a couple free android coding lessons.
create java/xml android template apps, and you can create a 'keystore' for your app, so you can publish your apps to the marketplaces like Google Playstore and Amazon.
- for creating Android Apps on your desktop computer.
Free to Install and Use
GoTo Android Studio
Learn more - Android Studio
The Java XML files we code(example codes) and the Android Apps we create in our Free
Tutorials are compatible with Android Studio and AIDE. Just choose Java XML as your Programming Language.
You May Like:
Make Sushi Rolls
Taste World Wines Flavours and Aromas