Skip to content

Instantly share code, notes, and snippets.

@shikleev
Last active May 16, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shikleev/59eaf31cde5e75e12b7270aff924f5c0 to your computer and use it in GitHub Desktop.
Save shikleev/59eaf31cde5e75e12b7270aff924f5c0 to your computer and use it in GitHub Desktop.
package info.yamm.lesson8;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Lesson 8");
myTextView = (TextView) findViewById(R.id.myText);
myTextView.setText("Привет!");
myButton1 = (Button) findViewById(R.id.myButton1);
myButton2 = (Button) findViewById(R.id.myButton2);
myButton3 = (Button) findViewById(R.id.myButton3);
myCheckBox = (CheckBox) findViewById(R.id.myCheckBox);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.myButton1:
myTextView.setText("Выбрана кнопка 1");
break;
case R.id.myButton2:
myTextView.setText("Выбрана кнопка 2");
break;
case R.id.myButton3:
myTextView.setText("Выбрана конпка 3");
}
}
};
myButton1.setOnClickListener(onClickListener);
myButton2.setOnClickListener(onClickListener);
myButton3.setOnClickListener(onClickListener);
myCheckBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (myCheckBox.isChecked())
myButton1.setEnabled(false);
else myButton1.setEnabled(true);
}
});
}
private TextView myTextView;
private Button myButton1;
private Button myButton2;
private Button myButton3;
private CheckBox myCheckBox;
//Зачем устанавливается параметр (View view), что он дает, какую функцию выполняет? Почему второй view с маленькой буквы
public void textClick1 (View view){
myButton1.setText(R.string.textButton1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment