1 // Copyright 2022 The Bazel Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.basicapp; 16 17 import android.app.Activity; 18 import android.os.Bundle; 19 import android.view.Menu; 20 import android.view.View; 21 import android.widget.Button; 22 import android.widget.TextView; 23 24 /** 25 * The main activity of the Basic Sample App. 26 */ 27 public class BasicActivity extends Activity { 28 29 @Override onCreate(Bundle savedInstanceState)30 protected void onCreate(Bundle savedInstanceState) { 31 super.onCreate(savedInstanceState); 32 setContentView(R.layout.basic_activity); 33 34 final Button buttons[] = { 35 findViewById(R.id.button_id_fizz), findViewById(R.id.button_id_buzz), 36 }; 37 38 for (Button b : buttons) { 39 b.setOnClickListener( 40 new View.OnClickListener() { 41 public void onClick(View v) { 42 TextView tv = findViewById(R.id.text_hello); 43 if (v.getId() == R.id.button_id_fizz) { 44 tv.setText("fizz"); 45 } else if (v.getId() == R.id.button_id_buzz) { 46 tv.setText("buzz"); 47 } 48 } 49 }); 50 } 51 } 52 53 @Override onCreateOptionsMenu(Menu menu)54 public boolean onCreateOptionsMenu(Menu menu) { 55 // Inflate the menu; this adds items to the action bar if it is present. 56 getMenuInflater().inflate(R.menu.menu, menu); 57 return true; 58 } 59 } 60