public class helloworldimage extends Activity {
/** Called when the activity is first created. */ @Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
ImageView HelloWorldImageView = new ImageView(this);
HelloWorldImageView.setImageResource(R.drawable.helloworld);
setContentView(HelloWorldImageView);
}
}
class Dog {
private String name = "hund";
public String toString() {
return this.name; // this referear här till en instans av klassen Dog
// dvs, just den _här_ instansen av klassen Dog
}
}
Dog d = new Dog(); // this där uppe är det samma som d (fast man har tillgång till alla instansvariabler)
this är även implicit, dvs om det inte finns en lokal variabel som överskuggar är det this.variabel.
Exempel:
class Dog {
private String name = "name";
private int age = 12;
public void calulateAge() {
int age = 7;
System.out.println("Local age: " + age);
System.out.println("Instance age: " + this.age);
}
}
EDIT:
I ditt fall handlar det om att klassen ImageView behöver en referece till ett objekt av typen Context av någon anledning.
(this instanceof Activity -> helloworldimage extends Activity && Activity extends Context (långt bort...))