-
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 1 commit
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 |
---|---|---|
|
@@ -11,20 +11,21 @@ | |
import android.widget.ImageView; | ||
import android.widget.RadioButton; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
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 TextView secondName; | ||
private TextView firstName; | ||
private ImageView photo; | ||
private RadioButton isFemale; | ||
private RadioButton isMale; | ||
private Button saver; | ||
|
||
private String[] image_names; | ||
private String[] imageNames; | ||
int pic_id; | ||
|
||
@Override | ||
|
@@ -33,29 +34,34 @@ protected void onCreate(Bundle savedInstanceState) { | |
this.setTitle("Addition"); | ||
setContentView(R.layout.student_addition); | ||
Random random = new Random(); | ||
Intent data = getIntent(); | ||
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); | ||
imageNames = 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()); | ||
pic_id = getResources().getIdentifier(imageNames[random.nextInt(5)], "drawable", getPackageName()); | ||
photo.setImageResource(pic_id); | ||
saver.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
|
||
boolean male = isMale.isChecked(); | ||
Intent intent = new Intent(); | ||
intent.putExtra("secondName", secondName.getText().toString()); | ||
intent.putExtra("firstName", firstName.getText().toString()); | ||
intent.putExtra("sex", male); | ||
intent.putExtra("photo", pic_id); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
if ((secondName.getText().toString().trim().length() != 0) || | ||
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 |
||
(firstName.getText().toString().trim().length() != 0)) { | ||
intent.putExtra("secondName", secondName.getText().toString()); | ||
intent.putExtra("firstName", firstName.getText().toString()); | ||
intent.putExtra("sex", male); | ||
intent.putExtra("photo", pic_id); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
else { | ||
setResult(RESULT_CANCELED, intent); | ||
Toast.makeText(this, "Please fill the FirstName and the SecondName fields!", Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,26 +3,26 @@ | |
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.text.TextUtils; | ||
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; | ||
import android.widget.Toast; | ||
|
||
public class InfoActivity extends AppCompatActivity implements View.OnClickListener { | ||
TextView secondName; | ||
TextView firstName; | ||
ImageView photo; | ||
RadioButton isFemale; | ||
RadioButton isMale; | ||
Button saver; | ||
Button deleter; | ||
private TextView secondName; | ||
private TextView firstName; | ||
private ImageView photo; | ||
private RadioButton isFemale; | ||
private RadioButton isMale; | ||
private Button saver; | ||
private Button deleter; | ||
|
||
private String[] image_names; | ||
private String[] imageNames; | ||
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.
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
@@ -31,20 +31,17 @@ protected void onCreate(Bundle savedInstanceState) { | |
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); | ||
imageNames = 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()); | ||
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; | ||
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 Все еще актуально |
||
|
@@ -60,22 +57,31 @@ 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); | ||
if ((secondName.getText().toString().trim().length() != 0) && | ||
(firstName.getText().toString().trim().length() != 0)) { | ||
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); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} else { | ||
setResult(RESULT_CANCELED, intent); | ||
Toast.makeText(this, "Please fill the FirstName and the SecondName fields!", Toast.LENGTH_LONG).show(); | ||
} | ||
break; | ||
|
||
case R.id.student_info__b_delete: | ||
intent.putExtra("button_code", 2); | ||
intent.putExtra("index", getIntent().getIntExtra("index", -1)); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
public class MainActivity extends AppCompatActivity { | ||
private ArrayList<Student> students; | ||
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. А нужно ли тебе здесь указывать тип? Лучше оперировать на уровне интерфейсов List students; |
||
private StudentAdapter studentAdapter; | ||
private String[] image_names; | ||
private String[] imageNames; | ||
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.
|
||
Random random; | ||
|
||
@Override | ||
|
@@ -26,7 +26,7 @@ protected void onCreate(Bundle savedInstanceState) { | |
setContentView(R.layout.activity_main); | ||
RecyclerView recyclerView = findViewById(R.id.activity_main__rv_students); | ||
|
||
image_names = getResources().getStringArray(R.array.image_names); | ||
imageNames = getResources().getStringArray(R.array.image_names); | ||
students = generateStudentsList(); | ||
studentAdapter = new StudentAdapter(this, students); | ||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); | ||
|
@@ -77,10 +77,10 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten | |
int pic_id = data.getIntExtra("photo", 1); | ||
boolean isMale = data.getBooleanExtra("isMale", false); | ||
Student student_to_change = students.get(index); | ||
student_to_change.secondName = secondName; | ||
student_to_change.firstName = firstName; | ||
student_to_change.isMale = isMale; | ||
student_to_change.photo = pic_id; | ||
student_to_change.setSecondName(secondName); | ||
student_to_change.setFirstName(firstName); | ||
student_to_change.setIsMale(isMale); | ||
student_to_change.setPhoto(pic_id); | ||
students.set(index, student_to_change); | ||
break; | ||
} | ||
|
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.