You are on page 1of 4

* button datatype : Button

* attatch button of the viewer to the code variable


variablename=findViewById(R.id.button name as in the viewer)
* text viewer data type : TextView
* text field data type : EditText
* to set a listener to the button:
setOnClickListener(new View.OnClickListener()) : hit enter and the code
will be automatically generated
* show some text on text viewer : textviewer variable name.setText("your text")
* get some text entered in the text field : String string name
edittext variable name.getText().ToString();
* to pass the ghot text into text field : text field variable name .setText(string
name into which the text is stored)
* if we want a specific text to be shown or added to the entered text : text field
variable name .setText("hello"+ string name into which the text is stored)
JAVA
* creating a new java class : file>new module>java module>class name
* it is present in packages > your module name > your class name
* every new java module must have a main : psvm
* command to print the line on terminal : System.out.println("your text");
* multiple values to print on terminal :
System.out.println("Name="+name+"age="+age+......)
* strings hold isEmpty() method which results or returns true or false
eg : string mani
mani="mani"
boolean empty = mani.isEmpty()
* another such function of such kind is contains
eg : string mani = "mani"
boolean contains = mani.contins("h")
* to use values folder strings : <string name="my_name">MANI</string>
if you want this string in the text editor of the xml you can access it
by @string/my_name
* to give on click event using a method > go to the text mode in the designer or
the activity_main.xml and under button quote the following text
make a method in mainactivity.xml as public void clickmethod(view v) **this view
v is very imp or else the app is going to crash
in the text mode under button add as android:onclick = "clickmethod"
* if we want to ue set text method to set integer value into the text field use :
money.setText(Integer.toString(money_counter)) where money counter is an integer
variable where it holds an integer to be shown
* or the other way is string.valueof(money_counter) > whatever may be the data type
of the money_counter it turns into string and sets the value >>>best method
* TOAST : it is viewing some msg for a short period of time > syntax :
Toast.MakeText(getapplicationcontent(),your msg,Toast.lenthlong/lengthShort) and in
next line .show ()** must imp
* to change color dynmically make a color under colors.xml in resources by using
<color name="mycolor">#CED(color name starts with #) as soon as you type ced a
color palette appears beside the code which on click allows you to get the hash
code of the color > access : R.color.my_color
or
* name.settextcolor(getresources.getcolor(r.color.mycolor))
* in strings folder while declaring a string to make something in bold just type in
<b> before and </b> after it
* ctrl+n : short cut in coding environment
* ide : integrated development environment
* in java the name of the method must be started with a capital letter'
* constructor must have same name as of class but without the word class
* if you are using a class and initialize it in another java class 1) if there is
no constructor declared in main class we can access it using . operator
example : if there is a class named Microphone we say Microphone mic = new
Microphone()
mic.color = ,jafv
2) if a constructor is specified explicitly then we use as Microphone mic = new
Microphone(blue)
* to use getters and setters : these are used to access some private variables of
the class
use ctrl+n and type in getters and setters and choose for which variables you
need getters and setters.
**** getters and setters must be in the main class so we can use them to access in
other classes.
in order to access them just type in Microphone.setname("GhMic")
* when you create new constructor in the main class we cannot access them using .
operator and cam only be accessed using the parameters
this is because the implicit constructor is lost.to make the user feasible to
access the variable just create one implicit constructor like public Microphone()
{};
* constructor overloading is done only when there are multiple constructors with
different number of accessing parameters list
ex : mic(string name,int id) and mic(int model,string color) these are two
constructors of same class user can overload or use constructor on his wish just by
givin the appropriate parameter values.
* to make a class inherit from another class we use inheritance
main class name : Main - has variables name,id,class,roll no.
sub class name : Sub - to inherit properties of main class just type in after
decleration of subclass as public void class Sub extends Main{}
example class name : ex ... to access variables of the Main class we can access
them by Sub class as sub.name , sub.id , sub.roll no etc....
* if the sub class has its own variables,in android studio they will be highlighted
with dark letters and inherited methods or variables with light color.
* if there is another class named supersub if supersub extends sub the supersub
class can also be used to access variables and methods of Main class.
* if we are accessing a method of supersub in the example class we can override it
like if it is not overrided the output of the example class will be decided by the
sub class...if we override it in the supersub and get the output using supersub
class in the example class the output will be the value defined in the supersub
class.
* it can be donw by going into the supersub class and type
* everytime if we wanted to set color to something create a color in the colors in
resources and use it as getresources.getcolor(r.colors.changer).
@Override
public int annualsalary(){
return super.getannual salary() + 10000
* here super is the programming term which gets the value or output of the
annualincome from the super class from which this class inherits the properties and
overrides it and if we use this supersub class to get output in the example class
we get the overrided output
* In android studio just in the supersub class go and type public function name you
want to override....then a list appear showing the little o and upward arrow which
specifies the programme that the function can be overrided.
* tostring() is an ultimate method that need not be specified inside of a class and
it comes in default while initializing the class.
* we can even override the tostring method inside of any class.
* in designer xml if we want to edit the properties go for single click and if we
want to change other attributes double click
* r.java class tht comes in built with the androuid studio connects the designer
with the java classes that we make
* example : if we create button in the designer we just use findviewbyid(r.id.<name
of the id you gave in the designer>)
* to make an integer into a string so as to set text just use string.valueof(name
of the integer variable)
* number format class usage : numberformat numfor<an example variable name> = new
numberformat();
this class helps to show the integer values in the currency format and the
currency symbol will be known to android device by which country it is in and puts
that symbol there
* permissons that app asks before running--- to ask for permissions,in
manifests.xml just add in <uses-permission android:name="<permission name>" and a
drop down list appears and you can choose the wanted permission from there
* R : android magestic resource class
* set content view of the main activity enables to create the view we can actually
see in the monbile
* if we want to use the strings that are given in the res/strings as a parameter
you must create a constructor with the parameter type of int since while passing
we pass as r.strings.<string name as in strings folder>
* creating an array of classes : <class name> arrayname[] = new <class name>[]{ new
<class name>(),....}
* this new <class name>() is the arrayname[0], and so on....
* if we want to add our custom icons or images to the project just drag and drop
them into the drawable folder in Android view> app>src>main>res>drawable....now
drag and drop the icon from file manager to the folder name<drawable
* since there are no update methods in the android studio just call the function
that you wanted to update every time if something needs to be changed
* just like creating a java class just go to the main folder where all the java
classes will be saved and right click and add new>activity>empty activity ...now
its created
* to jump from one activity to the other create Intent <own intent name> = new
Intent(<current activity name>.this,<jump activity
name>.class)=>(source,destination)
and in next line just pass this intent to startactivity(<own intent name>);
* To send data from one activity to the other just beore passing the startactivity
type=>intent.putextra and just from following list choose the function type you
want to send and in first parameter will be the keycode to send and recieve and
the second parameter will be the data to send...
* while recieving the data in other class use getintent().getstringextra(keycode of
data sent) and store it in another string so as to use in current activity...
* how to use a text entry field : use find view by id method to map it with code
and => <name>.gettext().tostring().trim() >> this trim gets all the junk stuff tht
user enters like spaces special charectors etc...,
* while recieveing the sent data using intent.putextra in the destination create a
bundle like >> Bundle <own name> = intent().getextras()
* this g<own name> of bundle type contains all the data sent from previous screen
and you can retrieve it using the key code as <own name>.getstring(<key code>

CONNECTING OUR APPS TO WEB

* Volley enables us to connect our app to the web >> android front end > api >
backend server >> api : application programme interface enables us to connect front
end to the backend server of the app
* to get volley into our app go to0 Gradle > build.gradle > add the dispencery from
the volley official website >> for now implementation
'com.android.volley:volley:1.1.1
* now click sync to sync the grade changes with the app
* whenever we use volley just add the internet permission in the android manifest
file
* json request object >> Jsonobjectrequest <name> = new
Jsonobjectrequest(Request.Method.Get<here instead of get there are so many
operations that we can perform>,<your db url>,null,new responcelistener,new
responceerrorlistener);
* to put all the data collected in a queue before creating a json request just type
in out of the main method as private RequestQueue <name>; and now in the main type
<name> = volley.newrequestqueue(this) >> now after the jason request creation type
<name of requestqueue>.add(<jsonrequestobject name>)
* JASON ARRAY : same as the creation of jasonobject request but when we want to
retrieve data since it is an array we need to create their individual objects so to
do that
just in the responce listener type >> for(int i = 0 ;
i<<jasonarrayname>.lengeth ; i++){ JasonObject <object
name>=responce.getjasonobject(i) } now we get an error and can be resolved by
using try and catch fix.....now if we want to use them just type
responce.getString("<key id as in the json array in the web>")
*

You might also like