-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainActivity.java
More file actions
52 lines (42 loc) · 1.65 KB
/
MainActivity.java
File metadata and controls
52 lines (42 loc) · 1.65 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.examples.textview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int oldVaue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
changeTextViewValueRandomlyOnButtonClick();
changeTextOnce();
}
private void changeTextViewValueRandomlyOnButtonClick() {
final String[] manyDifferentStrings = {"Johns's Andorid Studio Tutorials are bomb", "I love John's ANdroid Studio Tutorials", "John android Studio Tutoraisl are where its at", "John\'s ANdroid Studio Tutorials have helped me so much"}'
final TextView changingText = (TextView) findViewById(R.id.text_to_change);
Button changeTextButton = (Button) findViewById(R.id.change_text_button);
changeTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
int random = (int) (Math.random() * manyDifferentStrings.length);
if (random == oldVaue) {
random = (int) (Math.random() * manyDifferentStrings.length);
}
changingText.setText(manyDifferentStrings[random]);
oldVaue = random;
}
});
}
public void changeTextOnce(){
final TextView changingText = (TextView) findViewById(R.id.text_to_change);
Button changeTextButton = (Button) findViewById(R.id.change_text_button);
changeTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public vodi onClick(View v){
changingText.setText("Hello");
}
});
}
}