Difference between revisions of "Android udvikling Marts 2017"
From Teknologisk videncenter
(→VariabelTyper) |
(→Kode til at klikke på en knaP) |
||
Line 32: | Line 32: | ||
<source lang="Java"> | <source lang="Java"> | ||
− | |||
− | + | ||
+ | Button minKnap; | ||
+ | TextView mitTextView; | ||
+ | |||
+ | |||
+ | @Override | ||
+ | protected void onCreate(Bundle savedInstanceState) { | ||
+ | super.onCreate(savedInstanceState); | ||
+ | setContentView(R.layout.activity_main); | ||
+ | |||
+ | minKnap = (Button) findViewById(R.id.minKnap); | ||
+ | mitTextView = (TextView) findViewById(R.id.mitTekstFelt); | ||
+ | |||
+ | minKnap.setOnClickListener(new View.OnClickListener() | ||
+ | { | ||
@Override | @Override | ||
public void onClick(View v) { | public void onClick(View v) { | ||
//Insert code here. | //Insert code here. | ||
+ | String mitTal = "Hej Mads!"; | ||
+ | mitTextView.setText(mitTal); | ||
} | } | ||
}); | }); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
</source> | </source> |
Revision as of 14:49, 6 March 2017
Contents
Generelt
Underviserens navn: Mads Nielsen
Link til Android studio download: https://developer.android.com/studio/index.html
Hvis du vil benytte en virtuel android enhed, væld da Lollipop. (version 5)
Mandag
VariabelTyper
Variabel Type | værdi |
---|---|
String | Tekst |
int | Heltal |
double | kommatal |
AndroidStudio
Kode til at klikke på en knaP
Button minKnap;
TextView mitTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
minKnap = (Button) findViewById(R.id.minKnap);
mitTextView = (TextView) findViewById(R.id.mitTekstFelt);
minKnap.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
//Insert code here.
String mitTal = "Hej Mads!";
mitTextView.setText(mitTal);
}
});
}