Retrieve an image from internet...

           In this application,by pressing a button we can retrieve a image from internet by giving a link to the application code.For this we need a xml layout containing a button and a imageview widget.When the button is pressed,the image data is retrieved and showed in the imageview widget.Here is the xml code of the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Connect"></Button>

<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
      Now we will use three java class for this.In the first one named ImageReadMain ,we initialize the button and the imageview and define the onClick method of the button.In the second java class connection1 the code for connection is written in setNetwork() method.In the last one named Data class,we simply write a static bitmap variable,that we will use in previous two classes.

Now look at the ImageReadMain class...


package Image.Read.a;

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;

Connection with internet...

      In this application we connect with internet when a button is pressed.It gives a response code of 200 in LogCat view,when properly connected with server and page is found.
So,we take a xml layout with a button in it...And here is the code below..


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Connect"></Button>
<ImageView android:id="@+id/ImageView01" android:layout_height="100dip" android:layout_width="100dip"></ImageView>
</LinearLayout>


Here we use two java class.In the first one named MyConnection we initialize the button and add the onClick method and inside we call the callNetwork method of another class Connection.The MyConnection class is defined below: