08 Jun 2012, 16:01
Generic-user-small

Pieter Vlam (3 posts)

The book states that a basic understanding of Java is sufficient but I don’t know where nor how to acquire that required knowledge. There are so many information sources. What is relevant for Android as far as “Java” is concerned?

What is the “this” in:
{ ... setContentView(new GraphicsView(this)); ... }

Thanks in advance!

Pieter

15 Jun 2012, 18:39
Generic-user-small

Rushil Vig (4 posts)

Try checking out thenewboston’s youtube series on android. It helped me a lot to explain these small parts of java.

25 Jun 2012, 18:48
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

30 Jun 2012, 03:39
Dipesh pic_pragsmall

Dipesh Bhardwaj (1 post)

Let’s consider a simple program to understand it:
class Temp{ int x; void get(int x){ x=x; } void show(){ System.out.println(x); }
}
class xyz{ public static void main(String args[]){ Temp t = new Temp(); t.get(10); t.show(); }
}
Here Output will be “0”;
As will not go above the method void get and will not get the reference variable x.

But in case, to achieve it we use “this”. Here i representing the internal working of this by a another simple program:
class Temp{ int x; void get(int x, Temp t){ t.x=x; } void show(){ System.out.println(x); }
}
class xyz{ public static void main(String args[]){ Temp t = new Temp(); t.get(10,t); t.show(); }
}
O/P = 10

This is the actual internal working of this, in every non static method of java this is implicitly imported.

Now on Page 63: setContentView(new GraphicsView(this));

“(this)” is used to point the referrence to GraphicsView class of “onCreate” method, as in android display screen is taken up by an Activity, which hosts a View, which in turn host a canvas.

24 Jul 2012, 01:45
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

Thanks for the tip. Note you can use the < pre > and < code > formatting tags in this forum to make code look prettier.

  You must be logged in to comment