-
Notifications
You must be signed in to change notification settings - Fork 21
ДЗ_2_Сагадеева Светлана #22
base: master
Are you sure you want to change the base?
Changes from 8 commits
18aa368
a7111e7
e9591a0
2e62ca2
48c697d
7311696
09a82ad
e9b2d04
bf15075
da02c09
f920219
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
*.iml | ||
.gradle | ||
/local.properties | ||
|
@@ -11,3 +12,4 @@ | |
/build | ||
/captures | ||
.externalNativeBuild | ||
/.idea/ |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ru.ok.technopolis.students; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.telephony.RadioAccessSpecifier; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
import android.widget.RadioButton; | ||
import android.widget.TextView; | ||
|
||
import org.w3c.dom.Text; | ||
|
||
import java.util.Random; | ||
|
||
public class AdditionActivity extends AppCompatActivity implements View.OnClickListener { | ||
TextView secondName; | ||
TextView firstName; | ||
ImageView photo; | ||
RadioButton isFemale; | ||
RadioButton isMale; | ||
Button saver; | ||
|
||
private String[] image_names; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Стоит использовать camelCase |
||
int pic_id; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
this.setTitle("Addition"); | ||
setContentView(R.layout.student_addition); | ||
Random random = new Random(); | ||
Intent data = getIntent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем здесь интент? |
||
secondName = (EditText) findViewById(R.id.student_add__et_second_name); | ||
firstName = (EditText) findViewById(R.id.student_add__et_first_name); | ||
image_names = getResources().getStringArray(R.array.image_names); | ||
photo = findViewById(R.id.student_add__iv_photo); | ||
isFemale = findViewById(R.id.student_add__rb_female); | ||
isMale = findViewById(R.id.student_add__rb_male); | ||
saver = findViewById(R.id.student_add__b_save); | ||
pic_id = getResources().getIdentifier(image_names[random.nextInt(5)], "drawable", getPackageName()); | ||
photo.setImageResource(pic_id); | ||
saver.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лишняя строка |
||
boolean male = isMale.isChecked(); | ||
Intent intent = new Intent(); | ||
intent.putExtra("secondName", secondName.getText().toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. secondName.getText() может вернуть null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ошибки ввода пользователем (попытки добавить или изменить студента, оставив его с пустой фамилией или именем) обрабатываю в InfoActivity и AdditionActivity соответственно |
||
intent.putExtra("firstName", firstName.getText().toString()); | ||
intent.putExtra("sex", male); | ||
intent.putExtra("photo", pic_id); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package ru.ok.technopolis.students; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
import android.widget.RadioButton; | ||
import android.widget.TextView; | ||
|
||
import java.util.Random; | ||
|
||
public class InfoActivity extends AppCompatActivity implements View.OnClickListener { | ||
TextView secondName; | ||
TextView firstName; | ||
ImageView photo; | ||
RadioButton isFemale; | ||
RadioButton isMale; | ||
Button saver; | ||
Button deleter; | ||
|
||
private String[] image_names; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
this.setTitle("Editor"); | ||
setContentView(R.layout.student_info); | ||
secondName = (EditText) findViewById(R.id.student_info__et_second_name); | ||
firstName = (EditText) findViewById(R.id.student_info__et_first_name); | ||
image_names = getResources().getStringArray(R.array.image_names); | ||
photo = findViewById(R.id.student_info__iv_photo); | ||
isFemale = findViewById(R.id.student_info__rb_female); | ||
isMale = findViewById(R.id.student_info__rb_male); | ||
saver = findViewById(R.id.student_info__b_save); | ||
deleter = findViewById(R.id.student_info__b_delete); | ||
Intent data = getIntent(); | ||
int pic_id = data.getIntExtra("photo", 1); | ||
// int id = getResources().getIdentifier(image_names[pic_id], "drawable", getPackageName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
photo.setImageResource(pic_id); | ||
boolean male; | ||
boolean female; | ||
male = data.getBooleanExtra("male", false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ключи экстра лучше определить в виде констант, что бы избежать опечаток в написании There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gilgenbergg Все еще актуально There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем тут инициализация в 2 строки? Можно сделать одной |
||
female = !male; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не используется нигде |
||
secondName.setText(data.getStringExtra("second_name")); | ||
firstName.setText(data.getStringExtra("first_name")); | ||
if (male) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше ставить фигурные скобы в условии if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gilgenbergg Все еще актуально |
||
isMale.setChecked(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно прям поставить результат в радиобаттон isMale.setChecked(male); |
||
else | ||
isFemale.setChecked(true); | ||
saver.setOnClickListener(this); | ||
deleter.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(); | ||
switch (v.getId()) { | ||
case R.id.student_info__b_save: | ||
intent.putExtra("secondName", secondName.getText().toString()); | ||
intent.putExtra("firstName", firstName.getText().toString()); | ||
intent.putExtra("button_code", 1); | ||
intent.putExtra("index", getIntent().getIntExtra("index", -1)); | ||
intent.putExtra("photo", getIntent().getIntExtra("photo", 1)); | ||
intent.putExtra("isMale", false); | ||
// intent.putExtra("pic_id", 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. весь закомменченный код убран |
||
break; | ||
case R.id.student_info__b_delete: | ||
intent.putExtra("button_code", 2); | ||
intent.putExtra("index", getIntent().getIntExtra("index", -1)); | ||
break; | ||
default: | ||
break; | ||
} | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше в явном виде устанавливать видимость полей (public,private...)