0

Disclaimer: this is a homework assignment so please no direct answers, please point me in the right direcction.

I am trying to create a simple activity that changes between two pictures when the button is clicked. I tried the followoing implementation

package com.example.davidmiller.assignment2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

   Integer pic = 0;
   ImageView noleID = (ImageView) findViewById(R.id.nolePic);
   ImageView gatorID = (ImageView) findViewById(R.id.gatorPic);

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   }

   public void showMe(View view) {
      if(pic == 0) {
         noleID.setVisibility(View.INVISIBLE);
         gatorID.setVisibility(View.VISIBLE);
         pic = 1;
      }
      else {
         gatorID.setVisibility(View.INVISIBLE);
         noleID.setVisibility(View.VISIBLE);
         pic = 0;
      }
   }
}

However when I try running the activity my emulator says the Assignment2 has stopped working. Any help is appreciated.

David
  • 217
  • 4
  • 14
  • 1
    If you want a push in the right direction, here: http://stackoverflow.com/questions/23353173. If you want the likely cause and its solution, here: http://stackoverflow.com/questions/36446114. – Mike M. Jun 01 '17 at 02:07
  • @Mike Thanks for those links, helped me find my error. Now I am stuck with one last problem. In my activity_main.xml file I use layout_editor_absoluteX/Y to position to pictures but they just end up in the top left corner of the emulator. Is there any advice you can offer for that? – David Jun 01 '17 at 02:16
  • 1
    Yep: http://stackoverflow.com/questions/42594033, http://stackoverflow.com/questions/43017289. – Mike M. Jun 01 '17 at 02:17
  • 1
    @Mike Thanks for the help! – David Jun 01 '17 at 12:56

0 Answers0