• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.google.android.mobly.snippet.example2;
18 
19 import java.util.Locale;
20 import androidx.appcompat.app.AppCompatActivity;
21 import android.os.Bundle;
22 import android.view.View;
23 import android.widget.Button;
24 import android.widget.TextView;
25 
26 public class MainActivity extends AppCompatActivity {
27     private TextView mTextView;
28     private Button mButton;
29     private int mNumPressed;
30 
31     /**
32      * Attaches a simple listener that increments the text in the textbox whenever the button is
33      * pressed.
34      */
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         setContentView(R.layout.activity_main);
39 
40         mTextView = (TextView) findViewById(R.id.main_text_view);
41         mButton = (Button) findViewById(R.id.main_button);
42         mButton.setOnClickListener(new View.OnClickListener() {
43             @Override
44             public void onClick(View v) {
45                 mNumPressed++;
46                 mTextView.setText(String.format(Locale.ROOT, "Button pressed %d times.", mNumPressed));
47             }
48         });
49     }
50 }
51