​This android developer course is actually pretty fun! There are several hard parts, and a few “scratch my head” moments, but Rob does a great job of explaining what to do.
Here’s my latest creation:
https://www.mediafire.com/download/168pmpux75y8w9u

It is a simple app that changes the picture and gives you a popup (toast) when you click the button.
I am a bit proud of myself on this one, because I went above and beyond the task at hand (changing the picture) but also added the toast (from a previous lesson) and changed the icon (which I posted a “how to” on earlier). The great part is, Rob will teach you some principles, and then give you a related task that he didn’t specifically cover.
In this case, he showed us how to display an image, and then asked us to figure out how to change it. Fortunately, there is Google, or I would not have made it work! After you finish the challenge, you can continue through the video and watch Rob explain it, step by step. It’s funny how things that take me an hour he does in about 3 to 5 minutes!
Here is my ANDROIDMANIFEST.XML

[CODE]

   

       

           

               
               

           

       

   

[/CODE]
Then my MAIN.XML

[CODE]

[/CODE]
Finally, my MAINACTIVITY.JAVA

[CODE]

package com.mycompany.images;
import android.app.*;

import android.os.*;

import android.view.*;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.*;
public class MainActivity extends Activity 

{

Boolean flag=false;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}
//mess method is declared in XML file

//This function will call when we click on button

//and we have to pass View object in this method

//which will take id of clicked button
public void change(View v)

{

Toast toast = Toast.makeText(getApplicationContext(), “Changing Picture…”, Toast.LENGTH_SHORT);

toast.show();

ImageView iv=(ImageView)findViewById(R.id.mainImageView1);

//use flag to change image

if(flag==false)

{

iv.setImageResource(R.drawable.ic_launcher);

flag=true;

}

else

{

iv.setImageResource(R.drawable.kdf);

flag=false;

}

}

}

[/CODE]
To God be the glory, it even works! Thankfully, there were several helpful finds on stack overflow and other blogs from my Google search. I certainly do not want to take credit for another’s work! I just put all the pieces together.
Another important part of the equation is to put ic_launcher.png and kdf.png (or whatever you name your icons) into the drawable folder in your source.

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *