Hello. I want to make such a small application that will show pictures in turn. There are two buttons back and forth for displaying the next and previous picture. Now what I have done-> I created the class Who, which has the fields name (String) and photo (ImageView). Also made a constructor, Who(String name,ImageView photo){this.name=name; this.photo = photo}; Who(String name,ImageView photo){this.name=name; this.photo = photo};
Next in the main activity class, I created a couple of variables of type ImageView. For each, I used the setImageResourse method. Then I created as many variables of the 'Who' type and sent the name and a variable of the ImageView type. Then all these variables of the form Who I saved in an ArrayList of the Who type. Next, by creating the showCurrentPerson() method, I assign an image to my image . But the program did not start and displayed an error. Where am I wrong? Can't I Assign ImageView Variables? The following is the MainActivity:
public ArrayList<Who> list; public Button RightButton, WrongButton; public ImageView ImageOf; int counter = 0; int point = 0 ; TextView name; private ImageView i1, i2, i3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RightButton = (Button) findViewById(R.id.righButton); WrongButton = (Button) findViewById(R.id.wrongButton); ImageOf = (ImageView) findViewById(R.id.imageView) name = (TextView)findViewById(R.id.textView); i1.setImageResource(R.drawable.leo); i2.setImageResource(R.drawable.en); Who w1 = new Who("leo",i1); Who w2 = new Who("en",i2); list.add(w1); list.add(w2); showCurrentPerson(); } public void showCurrentPerson() { Who cur = new Who(); cur = list.get(counter); ImageOf = cur.photo; name.setText(cur.name); } public void Wrong(View view) { if(counter==list.size()) counter = 0 ; else counter++; } public void Right(View view) { point++; if(counter==list.size()) counter = 0 ; else counter++; }