Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

declaring variables views in java android

public TextView textView1 = (TextView) findViewById(R.id.textView1);
public Button button2 =  findViewById(R.id.button2);

// public/private ViewType VariableName = (casting types WHEN NEEDED) findViewById(R.id.idOfTheViewSpecifiedInXML)
// and so on...

//Note: Should be declared outside onCreate() so it can be used in other methods.
//e.g.:
		public TextView textView1; //declaration
		onCreate(){
			 ...
			 textView1 = findViewById(R.id.textView1);
				}
 
PREVIOUS NEXT
Tagged: #declaring #variables #views #java #android
ADD COMMENT
Topic
Name
3+3 =