https://stackoverflow.com/questions/30731121/how-can-i-return-an-arraylist-from-my-asynctask
class chargeCars extends AsyncTask<Void, Integer, ArrayList<Car>> {
private final OnCarsListener mListener;
ArrayList<Car> cars = new ArrayList<Car>();
public chargeCars(OnCarsListener listener) {
mListener = listener;
}
protected void onPreExecute(){
}
protected ArrayList<Car> doInBackground(Void... params) {
cars.add(new Car(1,"Car1");
cars.add(new Car(2,"Car2");
cars.add(new Car(3,"Car3");
Log.d("Size: ", "" + cars.size()); //It gives me the size equals to 3 -->Correct
return cars;
}
protected void onProgressUpdate(){
}
protected void onPostExecute(ArrayList<Car> cars){
if (mListener != null) {
mListener.onCarsCompleted(cars);
}
}
}
String Manipulation
Java String substring
String s1="javatpoint";
System.out.println(s1.substring(2,4));//returns va
System.out.println(s1.substring(2));//returns vatpoint
System.out.println(s1.substring(2,4));//returns va
System.out.println(s1.substring(2));//returns vatpoint
Java String indexOf() method example
https://www.javatpoint.com/java-string-indexofpublic class SubstringExample{
public static void main(String args[]){
String s1="ID=1001131141 Body Tem";
int index= s1.indexOf("Body",0);
System.out.println( index+"");
System.out.println(s1.substring(3,index));//returns va
}}
//To capture the ID 19787 from the string "19787 : chicken 10 5"
public class SubstringExample{
public static void main(String args[]){
String s1="19787 : chicken 10 5";
int index=s1.indexOf(":",0);
System.out.println( index+"");
System.out.println(s1.substring(0,index));// returns the ID 19787
}}
-------------------------------------
Java String charAt()
String name="javatpoint";
char ch=name.charAt(4);//returns the char value at the 4th index
System.out.println(ch);
char ch=name.charAt(4);//returns the char value at the 4th index
System.out.println(ch);
https://www.javatpoint.com/java-string-charat
For Dafid
//Partial codes
For Dafid
//Partial codes
//calculate GPA
double cGPA =0.0;
int totalCU=0;
select * from subjectlist
{
while cursor.next ()
{
int cu = Integer.parseInt ( ....getString("SubjCU"));
String sGrade = ( ....getString("SubjGrade"));
int gradePt =0;
if (sGrade.equals("A") )
{
gradePt = 4;
}
totalCU+= cu ;
cGPA += cu*gradePt
}
double gpa = cGPA /totalCU;
}
For Nuralif
//After click Pay button
//insert the ID and the Date and time into Sqlite DB
//Test it on your AVD
//If it works
Add one page in your report
Show the screenshot of the AVD and DDMS db to show that it works.
and the coding for Pay
#1 Pass the ID from QR code Page to Pay Page
see putExtra and getExtra
#2 Pay Page
i) getExtra for the prodID
example prodID = .............................
ii) get current date and time
public class SubstringExample{
public static void main(String[] args) {
String pattern = "MM/dd/yyyy";
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(pattern);
try {
java.util.Date date = format.parse("12/31/2006");
// System.out.println(date);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
// formatting
String todayDate = format.format(new java.util.Date());
System.out.println(todayDate );
}
}
//Compile by: javac SubstringExample.java
https://compiler.javatpoint.com/opr/test.jsp?filename=SubstringExample
iii) create table if not exists ......
shoppingCart (id, dateTime)
iv)insert into sqlite DB
insert into shoppingCart (id, dateTime) values ('"+ prodID + "','"+todayDate +"'")
#3 if works screenhsot the output of the AVD and DDMS db to show that it works
and put in your report.
//Luqman
public class SubstringExample{
public static void main(String args[]){
String s1="ID=10686888686 Car: Toyota 2000cc";
int index= s1.indexOf("Car",0);
System.out.println( index+"");
System.out.println(s1.substring(3,index));//returns va
}}
https://compiler.javatpoint.com/opr/test.jsp?filename=SubstringExample
//Khaidhir & Neo ZX
Lab13+ New activity (Search)
a) Search for places
b) display the name, lat/long, distance from current location in metres
//for Jody
// Random Number
public class SubstringExample{
public static void main(String args[]){
double num = Math.floor((Math.random() * 100) + 1);
int num2 = (int) num;
System.out.println(num2);
}}
For Nuralif
//After click Pay button
//insert the ID and the Date and time into Sqlite DB
//Test it on your AVD
//If it works
Add one page in your report
Show the screenshot of the AVD and DDMS db to show that it works.
and the coding for Pay
#1 Pass the ID from QR code Page to Pay Page
see putExtra and getExtra
#2 Pay Page
i) getExtra for the prodID
example prodID = .............................
ii) get current date and time
public class SubstringExample{
public static void main(String[] args) {
String pattern = "MM/dd/yyyy";
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(pattern);
try {
java.util.Date date = format.parse("12/31/2006");
// System.out.println(date);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
// formatting
String todayDate = format.format(new java.util.Date());
System.out.println(todayDate );
}
}
//Compile by: javac SubstringExample.java
//Run by: java SubstringExample
02/14/2018
https://compiler.javatpoint.com/opr/test.jsp?filename=SubstringExample
iii) create table if not exists ......
shoppingCart (id, dateTime)
iv)insert into sqlite DB
insert into shoppingCart (id, dateTime) values ('"+ prodID + "','"+todayDate +"'")
#3 if works screenhsot the output of the AVD and DDMS db to show that it works
and put in your report.
//Luqman
public class SubstringExample{
public static void main(String args[]){
String s1="ID=10686888686 Car: Toyota 2000cc";
int index= s1.indexOf("Car",0);
System.out.println( index+"");
System.out.println(s1.substring(3,index));//returns va
}}
https://compiler.javatpoint.com/opr/test.jsp?filename=SubstringExample
//Khaidhir & Neo ZX
Lab13+ New activity (Search)
a) Search for places
b) display the name, lat/long, distance from current location in metres
//for Jody
// Random Number
public class SubstringExample{
public static void main(String args[]){
double num = Math.floor((Math.random() * 100) + 1);
int num2 = (int) num;
System.out.println(num2);
}}