[Android] Views

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// MainActivity.java
public class MainActivity extends AppCompatActivity {
private Button mButton;
private TextView mTextView;

@Override
protected void onCreate(Bundel savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mButton = (Button) findViewById(R.id.mButton);
mTextView = (TextView) findViewById(R.id.mTextView);

// Change the title of the button
mButton.setText(R.string.button_name);

// Alternative to public function showMe
mButton.setOnClickListener(new View.OnClickListener()) {
@Override
public void onClick(View v) {
mTextView.setVisibility(View.VISIBLE);
mTextView.setText(R.string.show_text);
}
}
}

public void showMe(View view) { // Append showMe to the onClick event in the
mTextView.setVisibility(View.VISIBLE);
mTextView.setText(R.string.show_text);
}
}