« first day    last day (44 days later) » 

15:19
Hello bro @MohammedAoufZOUAG :D
15:35
Hey @Skizo :D
What do you do?
Did I successfully ping you ? xD
Yap
awesome
I'm working on a blog
Did I?
15:36
yes you did
Nice
I'm working with the JSON still xD
I can read the first array
no kidding xD
but the second seems like doesn't exist
lol
what other problems did you face ?
My json has 3 lists of arrays it means apple has apple list then it has more arrays and the second it's called Pear and it has Pear list and so
BUT I only can read the Apple list
seems like my for doesn't go ahead
it only reads the first one
15:38
hum
show me some code
& some JSON xD
I'm just able to print list 1
with this code
public static ArrayList<RedCajeroPOJO> ParseRedCajeroTipo (Context context, String tipo){
String sJson = loadJSONFromAsset(context);

ArrayList<RedCajeroPOJO> redCajeroList = new ArrayList<RedCajeroPOJO>();;
try {
JSONObject obj = new JSONObject(sJson);
JSONArray jsonMainArr = obj.getJSONArray("lists");
for (int i = 0; i < jsonMainArr.length(); i++) {
JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
//BUCLE PARA LOS LIST
JSONArray childJSONArray = childJSONObject.getJSONArray(tipo);
Toast.makeText(context, jsonMainArr.get(i).toString(), Toast.LENGTH_SHORT).show();
Tipo must be the list1, list2 etc
ok
what is your goal again ?
to read the "list1", "list2" & "list3" JSONArrays ?
I wanted to create a method that saying the name of the array
reads it
for more efficience you know?
I mean I have 3 arrays and I need stuff of those
Then when I press on an item it returns this name and then I call this method and I want to parse the data of that name
And then I add those with RedCajero etc... but it laggs a little bit I guess is because I'm putting the int with the name like I'm calling for example R.Drawable + String, and I think it laggs :S
15:50
I'm sorry
I didn't understand
What didn't understand?
what is your expected output ?
I'm kinda retarded :p
okay, pay attention
Activity 1 I parse to get the name of those 3 arrays output GOOD
Activity 2 parse to get the data of the item clicked (only works with the first item)
15:51
list1 list2 list3
works for list1 ?
Activity 1 shows paw,pew,piw
Activity 2 when I click on paw shows pawa pawb
When I click on pew it doesn't show anything
oh I see
it should show pewa pewb
I know
but it doesn't
because of tipo
what's tipo ?
list1, list2, list3
I'm passsing this as a parameter
15:55
got it
I will work it out in plain Java
& let you know of the result OK ?
ok
copy my method pls
if you want I re adapt for you
okey, I just need to adjust it according to my environment
since I'm not using Android Studio
just Java
Ya, I know
hold on
well I don't know what to put
instead of context
public static ArrayList<RedCajeroPOJO> ParseRedCajeroTipo (Context context, String tipo){
String sJson = loadJSONFromAsset(context);

ArrayList<String> redCajeroList = new ArrayList<String>();
try {
JSONObject obj = new JSONObject(sJson);
JSONArray jsonMainArr = obj.getJSONArray("lists");
for (int i = 0; i < jsonMainArr.length(); i++) {
JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
//LIST LOOP
JSONArray childJSONArray = childJSONObject.getJSONArray(tipo);
for (int j = 0; j < childJSONArray.length(); j++) {
Try this out
this method is for read json
public static String loadJSONFromAsset(Context ctx) {
String json = null;
try {

InputStream is = ctx.getAssets().open("cajeros.json");

int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");

} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;

}
16:11
it keeps reading only the first one GRRRR :(
okey look
first essay:
I get an exception
but it prints the expected output
Yap
same on me
try the second
not found
weird
exception + no output
looooooooooooool
weird...
16:15
what?
not weird
perfectly normal
hear me out:
ya?
last test of my theory...
(1 sec)
ok
And maybe there is other way to do it more efficient...
using org.json, this seems to be the best way
16:19
Because do you think it's a good idea create the objects (Array<String>) on the parser and then show them ?
Because my recycler view laggs when I'm scrolling
I don't think it's a problem
do the parsing once the activity is loaded
pass the list of strings to the adapter
then you can bind the data on the fly
that's what I did
I pass the strings to the adapter
But maybe it's because I do this :
public static int getId(String resourceName, Class<?> c) {
try {
Field idField = c.getDeclaredField(resourceName);
return idField.getInt(idField);
} catch (Exception e) {
throw new RuntimeException("No resource ID found for: "
+ resourceName + " / " + c, e);
}
}
method to get the drawable with a String
okey look
the problem is
in deed the tipo string that you pass in as an argument
& your JSON file is also problematic
What's wrong?
the thing is
when parsing the JSON file
for the example, tipo = "list2"
okey ?
16:28
yap
What happens?
consider yourself to be the JSON parser (lol I know)
okay I consider
JSONArray childJSONArray = childJSONObject.getJSONArray("list2");
this line
you, the JSON parser
I'll look for another array?
on childJsonObject?
16:30
Then?
you start looking inside the FIRST JSONObject for a JSONArray with the list2 name.
got it ?
(this is the first iteration of the loop == first JSONObject)
Yap
now it's your turn
post here the code of the first JSONObject
the first json object
is list1?
just post its code
(you're the parser, remember ?)
16:34
Yap
Let's go line by line
I'm the parser
JSONObject obj = new JSONObject(sJson);
Output : All the json
right?
ok
right. Next line
16:35
JSONArray jsonMainArr = obj.getJSONArray("redcajerosArray");
jsonMainArr (list1, list2, list3)
no?
JsonMainArr contains the arrays
JSONArray jsonMainArr = obj.getJSONArray("lists");
this is the next line
that reads all the lists
Yes
Next one : JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
reads the first JSONObject of the array
16:37
Yes (list1), right?
yep
now stop
Here is what you have now, Mr. parser xD :
xD
I don't print the next line?
no
{
    "id": "01",
    "name": "paw",
    "list1": [{
      "id": "A",
      "name": "pawa",
      "bar": "foo"
    }, {
      "id": "B",
      "name": "pawb",
      "bar": "foo"
    }]
  }
This is the first JSONObject of the array
right ?
yep
now print the next line
of the Java code
16:39
JSONArray childJSONArray = childJSONObject.getJSONArray(tipo);
which evaluates to
JSONArray childJSONArray = childJSONObject.getJSONArray("list2");
not found DANGER DANGER
ahaha wait wait
now Mr. parser
you start looking for a JSONArray with the name list2
in the JSONObject above
can you find one ?
nope
not list2
so what do you do ?
16:42
i++
no?
Oh, no I go this line : for (int j = 0; j < childJSONArray.length(); j++) {
?
@MohammedAoufZOUAG now with that loop I'm loofing for the list, no?
I'm back
sorry
np
yes
back to business
you are wrong
that's not what you do
you do not i++
once you don't find list2, you raise a JSONException
& the execution fails
16:51
Oh...
that's why
this only works for the first item
:D
see ?
Yap...
I see now
try switching the positions of the first & last JSONObjects
didn't know that it would stop
means?
means
that you need to restructure that JSON
Those JSONObjects already have an id property
so why naming them list1, list2, list3...
16:52
ye
isnt' necessary?
just name them list
like it used to be befoer
before*
done
Now I can ask for the Id?
now what you can do
if you are specifically targeting the 2nd list
You said that the three lists named list
right?
16:56
ok
but my question is how can I go to the list 2?
ArrayList<String> redCajeroList = new ArrayList<>();
try {
JSONObject obj = new JSONObject(json);
JSONArray jsonMainArr = obj.getJSONArray("lists");
for (int i = 0; i < jsonMainArr.length(); i++) {
JSONObject childJSONObject = jsonMainArr.getJSONObject(i);

int id = childJSONObject.getInt("id");
if(id == 2) {
JSONArray childJSONArray = childJSONObject.getJSONArray("list");
for (int j = 0; j < childJSONArray.length(); j++) {
JSONObject childJSONObjectB = childJSONArray.getJSONObject(j);
String name2 = childJSONObjectB.getString("name");
Ya but I have to do it with the 3 id?
such a nasty code xD
nope
this is a test
wait
now since we got rid of list1, list2, list3...
& replaced them with list
instead of calling your method with a String argument, call it with an Integer one
do you understand what I'm saying right now ?
that will be the Id
right?
yep
all clear now ?
17:03
Then I think it's good to do something like this
int idcjo = childJSONObject.getInt("id");
//BUCLE PARA LOS LIST
if(id==idcjo) {
//STUFF
}
}
id = parameter
Nice ^^
Since I have 3 arrays
remember the first occurrence constraint I showed you
17:05
you know why I had tipo?
Because when I click on a item from the first Activity
It returns to me the getText
then on my Activity2 I put getintent bla bla + " list"
and I thought i would work
but nope xD
I'm sure now you can get it done
Yap
I'll make a function that depends the name returns a number
then it will be the id xD
right?
LOL
and passing as a parameter of the intent
for example it's a list ok?
list 1
list 2
list 3
if I get the position of list1 instead of the name
it would work?
how would you call it in Java code & what would be the expected output ?
17:12
wait
I'm testing
graddling
:3
it shall be a piece of cake
the hard part is done
Yaaa
WAAAAA :D
Look my trick
It's on AS (it works)
sweet
what is it ?
17:15
On my adapter
int idnombrecajero = cardViewHolder.getAdapterPosition();
Intent i = new Intent(mContext, Activity2.class);
i.putExtra("IdCajero",idnombrecajero +1);
Activity2 : Bundle bundle = getIntent().getExtras();
int iSelectedItem = bundle.getInt("IdCajero", 0);
Got it?
What do you think it's better, getting the text and then a function that returns the 1,2,3 or X depends of the JSON
or this method?
I think the first choice is better
tricks require documentation :p
hahaha :D
next step
It's add a searcher on Acticity2 and filter those
But I think tomorrow :D
I'm tired now
Searcher
that shall be fun
I remember last time I wanted to implement one of those
didn't end so well :P
17:19
I never implement one
:O
Well, just once, but meh
Consider using a SearchView
Such a nice answer : WAWA
nice one in deed
Well I think I can implement it
it's well explained
totally
thanks for pointing it out
I needed it too
17:25
Np
thanks for your help 2 :D
:D
Talk to you later ?
Sure! :D
if you want something just ping me :D
 
4 hours later…
21:57
I couldn't wait
and I just implement the searcher
WOW too easy man
Just try it @MohammedAoufZOUAG, is super detailed
this guy deserves a monument xD
22:19
I'll certainly will try it out
Yaap
You know what I'm trying now?
I'm trying that if you type for example X and noone of the items of the List contains X
I want to add like a TextView saying : No result found :(
Oh man
I would like to join you on this quest
but I can't :(
I have a stupid presentation first thing tomorrow morning, I will present a blog to the class
Np haha
I'll do it and I'll show you how to do it then you can do it as well :D
Gl with your presentation ^^
Thanks, I appreciate it
:D
I'm having a heart attack right now :p
I'm running out of time
& I'm super bored
hahaha
22:28
I hate anything that has something to do with HTML, CSS, Javascript, PHP :3
You don't like?
I don't like any of them
And you love Java, right? xD
Big fan, yeah :D
hahaha nice :D
22:31
you know what
we should work on an Android app, together someday
Would be FANTASTIC :D
I would really like to :D
Same
By the way, got it :P
I know how to put TextView Programmatically when the query is different to the all of the items of the list
^^
22:36
oh niice
is it difficult to implement ?
I mean, do you have to deal with the positioning of the TextView in Java code ?
The problem that I have is that I only have a `RecyclerView` right? then the steps are :
RelativeLayout rt = findView
Then Add a TextView programmatically when query isn't equal, and autommatically it puts the TextView on the top of the Activity, then I have to play with margins, gravity, etc... and it works... I don't know if it's the best way to do it, but it does the function :P
Otherway could be creating a new xml and then setContentView(R.layout.theXml);
but I don't know what's better xD
I think the first one is the most optimal
I mean, loading a new layout file could be a bit laggy; don't you think ?
Yap :/
I will ask you later for help concerning this thing later
Okay :D
22:42
+1 for implementing this feature
Yap ^^
I'm going to sleep... tomorrow I have to go to uni early and I must sleep xD
We can talk tomorrow!
See you later bro ^^
I'll catch up with you later, good night ! :D
Good night mate good luck with your presentation :)
thank you so much :D

« first day    last day (44 days later) »