Skip to content

Commit 09222d8

Browse files
committed
Corregido fallo cuando no había nada seleccionado
1 parent 072d399 commit 09222d8

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

ReciclerView/app/src/main/java/space/harbour/reciclerviewsample/MainActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ private void populateSuperheroList() {
4949
public void onClick(View view) {
5050
// Get selected hero from the list
5151
Superhero selectedCharacter = adapter.getSelectedSuperhero();
52+
if (selectedCharacter == null)
53+
Toast.makeText(this, R.string.a_superhero_must_be_selected, Toast.LENGTH_LONG).show();
54+
5255
Toast.makeText(this, selectedCharacter.getFullName(), Toast.LENGTH_SHORT).show();
5356
}
5457
}

ReciclerView/app/src/main/java/space/harbour/reciclerviewsample/Superhero.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package space.harbour.reciclerviewsample;
22

3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
37
/**
48
* Superhero
59
*/
@@ -18,15 +22,28 @@ public String getName() {
1822
return name;
1923
}
2024

25+
public void setName(String name) {
26+
this.name = name;
27+
}
28+
2129
public String getSurname() {
2230
return surname;
2331
}
2432

33+
public void setSurname(String surname) {
34+
this.surname = surname;
35+
}
36+
2537
public String getSuperHeroeName() {
2638
return superHeroeName;
2739
}
2840

41+
public void setSuperHeroeName(String superHeroeName) {
42+
this.superHeroeName = superHeroeName;
43+
}
44+
2945
public String getFullName() {
3046
return name + " " + surname;
47+
3148
}
3249
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">ReciclerViewSample</string>
3+
<string name="a_superhero_must_be_selected">A superhero must be selected</string>
34
</resources>

0 commit comments

Comments
 (0)