Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,298 members, 7,819,001 topics. Date: Monday, 06 May 2024 at 09:50 AM

Learn How To Develop Android Apps With Your Android Phone - Phones (6) - Nairaland

Nairaland Forum / Science/Technology / Phones / Learn How To Develop Android Apps With Your Android Phone (19868 Views)

Learn To Develop Android & Ios Apps Without Writing Codes(free Tutorial) / How To Lock Apps With Fingerprint On Any Infinix Phone Running Android 7 Nougat / How To Lock Your Apps With Password Or Fingerprint On Infinix XUI 2.0 (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (Reply) (Go Down)

Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 11:49am On Jul 11, 2016
Not too bad so far.

Re: Learn How To Develop Android Apps With Your Android Phone by Mrluv(m): 6:45pm On Jul 11, 2016
DavidTheGeek:
GETTING STARTED...
You all are welcome to the thread. Lets put things in place so we can start asap.

Things you'll need to participate in this tutorial class:
1. Your android phone must be running on at least android version 2.3.
2. AIDE app. (Go to playstore, search and download "AIDE" on your phone)
bro i cant acess play store can u upload the app here
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 2:23pm On Jul 12, 2016
yorex2011:
The second method of creating string. i.e using strings.xml is a better practice as it allows for cleaner coding and easy text replacement whenever you want to replace, it is also good when you want your app in anotherllanguage as you can easily just translate everything in ur strings.xml to the new language while maintaining the names of each string.
Also, by using the 2nd method, you can apply style (bold and italic) at different points of a text.

Example:

<string name="title"><b>This text is a bold text</b> while this other <i>text here is italic</i></string>

Bold - <b>text here</b>
Italic - <i>text here</i>

yorex2011 i see you. Thanks for the contribution
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 2:29pm On Jul 12, 2016
Reyginus:
Not too bad so far.
Have you added style and increased the text size?
Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 2:30pm On Jul 12, 2016
DavidTheGeek:

Have you added style and increased the text size?
No. Let me try it now. I'm not using the second method btw.
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 2:36pm On Jul 12, 2016
Reyginus:
No. Let me try it now. I'm not using the second method btw.
Okay. Well the 1st method is quicker when coding. Tho it's not adviceable to use it for big projects.
Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 2:51pm On Jul 12, 2016
DavidTheGeek:

Okay. Well the 1st method is quicker when coding. Tho it's not adviceable to use it for big projects.
Why?
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 3:03pm On Jul 12, 2016
Reyginus:
Why?
Read yorex2011 post above.
Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 3:11pm On Jul 12, 2016
How about this, DavidTheGeek? I borrowed your colour codes.

Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 3:15pm On Jul 12, 2016
Jinf:
LETS CONTINUE....
We're still working on our app.

Android TextView
A TextView displays text to the user.

The following are the important attributes related to TextView control. You can check Android official documentation for complete list of attributes.

Attribute...
* android:text - display text.
eg android:text="I'm a Text"

* android:id - This is the ID which uniquely identifies the control.
eg android:id="@+id/text"

* android:textSize - Size of the text.
eg android:textSize="10sp"

* android:textStyle - Style (bold, italic) for the text. You can use one or more of the following values separated by '|' eg bold|italic.
eg android:textStyle="bold"

*****************
There are two ways to input a text. It's either you write it directly:
android:text="I'm a text"

OR

Create a string in resources...
<string name="text">I'm a Text</string>

....and reference...
android:text="@string/text"

Check the strings.xml file res/values folder for better understanding.
***********************

Edit your code and replace the hello world text
1ST METHOD...

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do not love one, not two. But love the one who loves you TOO.\nDo not love three, not four. But love the one who loves you MORE.\nDo not love five, not six. But love the one who truly STICKS.\nDo not love seven, not eight. But love the one who is willing to WAIT.\nDo not love nine, not ten. But love the one who\'ll love you until the END."
android:textColor="#ff0000" />

*** \n is line break
*** \ before " and ' else an error would occur

2ND METHOD...
In main.xml edit textview

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/love"
android:textColor="#ff0000" />

In strings.xml file res/values

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="love">Do not love one, not two. But love the one who loves you TOO.\nDo not love three, not four. But love the one who loves you MORE.\nDo not love five, not six. But love the one who truly STICKS.\nDo not love seven, not eight. But love the one who is willing to WAIT.\nDo not love nine, not ten. But love the one who\'ll love you until the END.</string>
<string name="app_name">MyFirstApp</string>
</resources>

ASSIGNMENT...
Play around with the TextView.
Add style (bold or italic) and increase the text size.
Where is the string.xml file? Or do I create it myself?
Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 3:20pm On Jul 12, 2016
..
Re: Learn How To Develop Android Apps With Your Android Phone by yorex2011: 7:16pm On Jul 12, 2016
Reyginus:
Where is the string.xml file? Or do I create it myself?
Its in the res folder
Re: Learn How To Develop Android Apps With Your Android Phone by phensbassey: 1:44am On Jul 13, 2016
DavidTheGeek:
LETS CONTINUE.... Android - User Interface (UI) Controls

User Interface simply means what you see on the screen.

A View is an object that draws something on the screen that the user can interact with and a ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the user interface.

Layout(s) are defined in an XML file which offers a human-readable structure for the layout

In the main.xml file that was created on aide, ViewGroup is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>

LinearLayout is a view group that aligns all children (view objects eg TextView) in a single direction, vertically or horizontally.

While View object is:
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a TextView" />

TextView is for showing text.

****************************************

There are a number of View objects provided by Android that allow you to build the user interface for your app.
For example: TextView, EditText, Button, ImageView etc.

In this tutorial, we'll be working with TextView & Button.

***************************************

TextView
This control is used to display text to the user.

Button
A button can be pressed, or clicked, to perform an action.

******************

A view object may have a unique ID assigned to it which will identify the View object uniquely within the View Group.
The syntax for an ID, inside an XML tag is − android:id="@+id/text_id". (Bolded in TextView code above)

LETS GET TO WORK...
In this tutorial, we will buid a simple app that shows a Text and a Button. When the button is clicked, a toast message would show on the screen.

EDIT MAIN.XML.... ADD BUTTON
By defult, there's a TextView already, simply add betton code uder... like this...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/click_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />

</LinearLayout>

Check image below to see how your main.xml file should look now....

Let's add a background color...
Add this android:background="#ffffff" code to in <LinearLayout........

Also lets add color to our text....

Add this android:textColor="#ff0000" code to in <TextView........

Click menu and select Run.
Install app.

App background should be white. Text should be red and a button should be visible now.

Let me know if you got it right, so i'll continue.
here s a screen shot of mine its showing me eror pls tel me what idid wrong

Re: Learn How To Develop Android Apps With Your Android Phone by richez25(m): 5:42am On Jul 13, 2016
DavidTheGeek:
Hey guys,

So, not everyone can easily afford a laptop BUT that shouldn't stop you from doing something cool... Like becoming an android developer, building apps for fun and even earning extra cash while doing it.

I'm thinking of teaching guys (and ladies of course) who want to learn android development how to build apps using their android phone.

What do you guys think about this idea?
Indicate if you're interested and also follow this thread, we'll use it for planning.

Add me to the whatsapp group, wud be easier to relate there..
08067182848
Re: Learn How To Develop Android Apps With Your Android Phone by Nobody: 8:28am On Jul 13, 2016
phensbassey:
here s a screen shot of mine its showing me eror pls tel me what idid wrong
Create a gap using the symbol _ between your Text Colour like the others.
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 10:20am On Jul 13, 2016
phensbassey:
here s a screen shot of mine its showing me eror pls tel me what idid wrong
Copy and paste your code here.
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 10:23am On Jul 13, 2016
Reyginus:
How about this, DavidTheGeek? I borrowed your colour codes.
Not bad. The background color tho
Re: Learn How To Develop Android Apps With Your Android Phone by xtophy(m): 11:20am On Jul 13, 2016
Re: Learn How To Develop Android Apps With Your Android Phone by xtophy(m): 11:31am On Jul 13, 2016
i changed the colour code

Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 11:46am On Jul 13, 2016
MOVING ON.... BUTTON
We're still working on our app.

Button

A Button is a Push-button which can be pressed, or clicked, by the user to. perform an action.

Attributes
The following are the important attributes related to Button control. You can check Android official documentation for
complete list of attributes.

* android:text - This is the Text to display.
android:text="Click Me"

* android:id - This supplies an identifier name for this view
eg android:id="@+id/button1"

* android:onClick - This is the name of the method in this View's context to invoke when the view is clicked.
eg android:onClick="showToast"

There are 2 ways to respond to a button click.

1. Using the Button onClick attribute
2. Registering an onClick Event listener

Lets use the Option 1 first...
To respond to button clicks using onClick attribute, you need to create a method in your activity (in this case MainActivity.java) and then invoke it in your Button

package com.learning.myfirstapp;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class MainActivity extends Activity
{
/** Called when the activity is first created. */
Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/**
setContentView(R.layout.main);
the code means you're telling MainActivity to load (show) res/layout/main.xml

If you have lets say two layouts, main and secondlayout. To load "secondlayout" that code would be
setContentView(R.layout. secondlayout);
**/
}

// Create a method for the Button onClick attribute

public void showToast(View v) {
Toast.makeText(getBaseContext(), "Hey! You clicked me", Toast.LENGTH_LONG).show();
}


public void showToast(View v)

showToast is the name i chose to call the method i created. You can name it anything you like.


In your main.xml, add onClick attribute and invoke the method:

android:onClick="showToast"

**********

Click menu and Run.

Open your app and click the button. A toast message should appear.

Re: Learn How To Develop Android Apps With Your Android Phone by deekseen(m): 1:35pm On Jul 13, 2016
I got this! (see attached picture).

However, the text on the button isn't displaying well and I will want the sentences in red and green to display on different lines.

What am I not doing right?

Re: Learn How To Develop Android Apps With Your Android Phone by phensbassey: 1:39pm On Jul 13, 2016
DavidTheGeek:
Copy and paste your code here.
here it is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:background="#ffffff" andriod:orientation="vertical">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:textColor="#ff0000"/>
<Button android:id="@+id/click_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me" />
Re: Learn How To Develop Android Apps With Your Android Phone by deekseen(m): 1:45pm On Jul 13, 2016
Here's my code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="When I saw the colour RED, I bled."
android:textSize="10sp"
android:textStyle="italic"
android:textColor="#ff0000"/>\n

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="When I saw the colour Green, I screamed"
android:textSize="10sp"
android:textColor="#008000"/>

<Button
android:id="@+id/click_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:textSize="20sp"
android:onClick="showToast"
android:textColor="#ffffff"/>

</LinearLayout>

I had to create 2 TextViews for the different colors because I couldn't combine them in one TextView.

The bigger the text in the sentences, the smaller the button.
Re: Learn How To Develop Android Apps With Your Android Phone by xtophy(m): 2:49pm On Jul 13, 2016
Reyginus:
Create a gap using the symbol _ between your Text Colour like the others.
dats also an error bro...wat i noticed is dat it is textSize not textsize, textColor not textcolour
Re: Learn How To Develop Android Apps With Your Android Phone by Jinf: 8:51pm On Jul 13, 2016
phensbassey:
here it is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
andriod:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#ff0000"/>

<Button
android:id="@+id/click_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
That's where your error is. You mis-spelt android. Correct it.

~ DavidTheGeek
Re: Learn How To Develop Android Apps With Your Android Phone by Jinf: 9:01pm On Jul 13, 2016
deekseen:
Here's my code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="When I saw the colour RED, I bled."
android:textSize="10sp"
android:textStyle="italic"
android:textColor="#ff0000"/>\n

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="When I saw the colour Green, I screamed"
android:textSize="10sp"
android:textColor="#008000"/>

<Button
android:id="@+id/click_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:textSize="20sp"
android:onClick="showToast"
android:textColor="#ffffff"/>

</LinearLayout>

I had to create 2 TextViews for the different colors because I couldn't combine them in one TextView.

The bigger the text in the sentences, the smaller the button.
You didn't add an orientation to your layout. By default it's horizontal that's why the button would disappear if the text is long. What you need is vertical.

add "android:orientation="vertical" in LinearLayout.

CORRECTION: \n should not be added outside, it should be inside TextView.

~DavidTheGeek
Re: Learn How To Develop Android Apps With Your Android Phone by shakrullah(m): 11:37pm On Jul 13, 2016
DavidTheGeek:
Hey guys,

So, not everyone can easily afford a laptop BUT that shouldn't stop you from doing something cool... Like becoming an android developer, building apps for fun and even earning extra cash while doing it.

I'm thinking of teaching guys (and ladies of course) who want to learn android development how to build apps using their android phone.

What do you guys think about this idea?
Indicate if you're interested and also follow this thread, we'll use it for planning.
I am in sir
Re: Learn How To Develop Android Apps With Your Android Phone by deekseen(m): 2:17pm On Jul 14, 2016
Jinf:

You didn't add an orientation to your layout. By default it's horizontal that's why the button would disappear if the text is long. What you need is vertical.

add "android:orientation="vertical" in LinearLayout.

CORRECTION: \n should not be added outside, it should be inside TextView.

~DavidTheGeek
Corrected. Thanks.

1 Like

Re: Learn How To Develop Android Apps With Your Android Phone by destino24(m): 9:51pm On Jul 14, 2016
Earth2Metahuman:
is it based on WYSIWYG or just regular coding?

Regular coding, but in a more organised way
Re: Learn How To Develop Android Apps With Your Android Phone by Toluene15: 1:33pm On Jul 15, 2016
Next..
How do we make the "<button" respond?

Re: Learn How To Develop Android Apps With Your Android Phone by pators(m): 4:40pm On Jul 15, 2016
cool i really need guidance on C#
Re: Learn How To Develop Android Apps With Your Android Phone by DavidTheGeek: 2:35am On Jul 16, 2016
Toluene15:
Next.. How do we make the "<button" respond?
I've posted that already. Check my previous posts.

(1) (2) (3) (4) (5) (6) (7) (8) (9) (Reply)

Internet Users : Nigeria Ranked #1 In Africa , #10 In The World / Etisalat Sues MTN Over Visafone Acquisition / Google’s Equiano Submarine Cable To Begin Operations In Nigeria By December

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.