Conversation started Mar 14, 2018 at 14:27.
Mar 14, 2018 14:27
@Ramona you know you can ask me stuff here too, right? :D
Connection issues, those were supposed to be in a different order
Mar 14, 2018 14:49
@PrincessLuna
but since i have 20 questions in 20 Fragments it is no point to set this public void onCheckedChanged 20 times in 20 Fragments, right?
Brb, gtg home. I'll answer then
ok, no problem.
Mar 14, 2018 15:14
and I'm back
great.
If you pass a question ID you can use that to find the right checked state for a given question
but it this code there is nothing abt ID, right?
yet it still works.
you only save one though
but in next Fragment I have...
RadioGroup rg1  = (RadioGroup) view.findViewById(R.id.radioGroup1);
        rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.radioButton2) {
                    Toast.makeText(getActivity(), "True", Toast.LENGTH_SHORT).show();
                    checked[1] = true;
                    answer[1] = true;
                } else {
                    checked[1] = true;
and checked[2] in next one and so on..
Mar 14, 2018 15:21
oh god, you have one fragment for each question?
you really need to add abstraction, or you'll code yourself to death
yes.. mistake i made a bit ago :) now trying to fix it :)
just wondering looking at this code how come that there are values (which button is checked) saved in this checked variable .how is it possible?
oh
you're asking how it works?
yes :)
Do you know what arrays are and how they work? (asking so I know what to tell you and how :) )
arrays more less yes :) before you explain ..but here we have no arrays in this case.
Mar 14, 2018 15:31
Actually, you do
static boolean[] checked = new boolean[NUMBER_OF_QUESTIONS];
That is an array
hmmm
??really?
yeah
You may have confused it with a List, but that's an array
the general definition is:
ClassOrPrimitive[] varName = new ClassOrPrimitive[arraySize]
ClassOrPrimitive varName[] = ========----==========
Lists are wrappers for Arrays, as Arrays have a static size
if you have an int[] x = new int[10], using int[10] or higher throws an exception (remember, indexes start at 0, meaning size of 10 is 0-9. General size definition: 0 to size - 1)
anyways, this means when you call checked[someINdex] and change the value, you change a specific part of that array
reading...
"Lists are wrappers for Arrays, as Arrays have a static size" ....static size means fixed..not changable,right? and "list are wrappers..."?
well, it means you can't increase the amount of elements in the array without going through some complicated re-calculations (you can't just say array.add(item) and the size increases)
Lists are wrappers, as they hold an array. The size of the array is changed by the list as needed. Arrays are a primitive datatype, while lists are objects
so it is like arrays inherit from lists..?
Mar 14, 2018 15:40
no, I mean:
class List<T>{//<T> is a generic type, meaning anything basically
    T[] data = new T[initialSize];
    void add(T item){
        //size check
       //increase if necessary and add
    }
That's an extremely simplified version of a List class, but you get the idea
(if you don't I just suck at explaining :D)
so you can add to objects but not to arraylist
(or i am a bad student) :)
add(T item) means adding item to variable 'data' of object type T?
@Ramona no, you can add to a list by calling a method, but to add more items to an array you have to expand the size of it. Which is what the list class does in add
@Ramona Yes
Which is defined with the diamond operator (<>, example: List<Object> ...)
@PrincessLuna oh yes..that is the language understandable to me :)
@Ramona No, I just generally suck at explaining because I find it hard to figure out what other people know. I.e. terminology is a massive pitfall when I explain stuff
one sec..i will write it down..
Mar 14, 2018 15:46
@Ramona Good! :)
slow down before i get lost :)
so what is the method to 'expand' this size of list?
One sec
gotta boot Android Studio first, which means I have to kill the bot (it uses a surprising amount of memory :D)
AS?
i have 4GB here and AS is really slow :)
I have 8 (gonna upgrade eventually though)
But I've been working on some neural network (AI) stuff recently, which easily grabs a lot of RAM. So does Gradle, so I have to turn off the neural net to run Android Studio
:) get yourself an extra computer
Mar 14, 2018 15:55
Too expensive
i recently ran out of memory on my old phone samsung galaxy ace :) only because google play store takes a lot of space with its uprades
:)
@Ramona :
private void grow(int minCapacity) {
    // overflow-conscious code
    int oldCapacity = elementData.length;
    int newCapacity = oldCapacity + (oldCapacity >> 1);
    if (newCapacity - minCapacity < 0)
        newCapacity = minCapacity;
    if (newCapacity - MAX_ARRAY_SIZE > 0)
        newCapacity = hugeCapacity(minCapacity);
    // minCapacity is usually close to size, so this is a win:
    elementData = Arrays.copyOf(elementData, newCapacity);
}
i think..this is the reason anyway :)
ok...
reading..
what is this now...actually?
TL;DR: It calculates the new capacity necessary, copies the elements over to a new list (because you can't increase it, but you can move the elements over to a new list with a different size), and sets the array in the List class (elementData is an array of the data)
ok..reading....
>>1 means adding or moving..?
Mar 14, 2018 16:01
>> is a bitshift operator
shifts from list 0 to list 1?
sorry for this question :)
no, it changes the binary representation of oldCapacity. TBH, I'm not quite sure how it works
gosh..hard to grasp this terminology :) anyways...
so this is the example
of method which increases arrayList?
binary is 0s and 1s, which al ldata is represented by. Bitshifting is moving those bits
@Ramona elementData = Arrays.copyOf(elementData, newCapacity);
yes..
how to read..this line?
copyOf(elementData, newCapacity)
Mar 14, 2018 16:06
Arrays is a class with etc. array utils
copyOF is a method that returns a copy of an array (here: elementData) with a new capacity
and newCapcity is....?
The new capacity
Idk what else to tell you :D
as simpl as that :)
so this method returns a copy of an array and stores in elementData?
Mar 14, 2018 16:09
yeah
elementData is the array the list class holds
wait..digesting... :)
so this (elementData - is the variable of OLD array and now we save it in a new 'elementData' = ?
no, you just override it
it's like saying:
int n = 5;
n = 7;
oh i see.
and why we need this second parameter 'newCapacity'?
to define the new size of the array
ok:)
uff :)
writing...
the thing is that the more you write down the more you cant find cos its gets complicated :)
so going back to this checed.. you wrote "when you call checked[someIndex] and change the value, you change a specific part of that array" what it means? and again.. how we store these values in this checked variable?
Mar 14, 2018 16:21
well, when you create an array like this:
boolean[] x = new boolean[10]
you essentially create this data stricture:
{ false, false, false, false, false ... } //10 items total
when you say x[3] = true, it changes to:
{ false, false, false, true, false, false, false ...}
if you then change x[0] = true, you get:
{true, false, false, true, false, false...
if you use objects, it's null though
wow... :)
so when we get value from first question it is stored in 0 index of this array, right?
and etc..
so this is how it is stored there?
so now to check now if the answers given by user are the right once we should...
?
do 'rightAnswers' array and compare?
checked v. rightAnswers?
Mar 14, 2018 16:31
yeah
this part of code looks like this (dont mind these fragments)
what you think?
would you make any changes?
i didnt write that code to be clear :)
cant grasp what this part means
if (isAllAnswered) {
                    boolean isGoodAnswer = checkAnswers();
@Ramona aside converting the 42 different fragments to a single class, no :) Looks good ^^
@Ramona isAllAnswered is a boolean
writing if(someBoolean) is the same as if(someBoolean == true)
so if all answers are in the same positions (==) as/with checkAnswers..?
checkAnswers just checks whether or not it's right (I think). Can't tell without more context
 
Conversation ended Mar 14, 2018 at 16:46.