-
-
Save udacityandroid/797532fc79eed21d801e to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity { | |
... | |
public void voteUdacicola(View view) { | |
int udacicolaVotes = 0; | |
udacicolaVotes = udacicolaVotes + 1; | |
} | |
public void votePepcity(View view) { | |
int pepcityVotes; | |
pepcityVotes = pepcityVotes + 1; | |
} | |
public void showMeVotes(View view) { | |
display(udacicolaVotes + " vs. " + pepcityVotes); | |
} | |
... | |
} |
can somebody please provide full code of xml and java for these examples............... i am getting very confused in this lesson 3
Both of variables are local and both of them must be global for reachable from anypoint.
having error
package com.example.ummurasul.practice;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int pepsiVotes = 0;
int spriteVotes =0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public void voteUdacicola(View view) {
spriteVotes = spriteVotes + 1;
display1(spriteVotes);
return;
}
public void votePepcity(View view) {
pepsiVotes =pepsiVotes + 1;
display(pepsiVotes);
return;
}
}
**public void display(int p) {
TextView t1 = (TextView) findViewById(R.id.cocacola);
t1.setText("" + p);
}
public void display1(int c) {
TextView t2 = (TextView) findViewById(R.id.pepsi);
t2.setText("" + c);
}**
the error is on de above code
@Kukkulum
A global variable is initialized at the starting of the code it is global means other methods can be used this variable but local variable is initialized inside a method and there local members can used it not all the methods.
Thank you for your explanation. It is helpful to understand the difference.
best android course on this planet
very nice course
the parent layout is linearLayout vertical