urgent-not able to display remote images in gallery

All your problems with Audio, Video and Images.

urgent-not able to display remote images in gallery

Postby android_anu » Wed Apr 07, 2010 1:15 pm

i am storing the imagesurl in an arrayadapter. i want to display all the images that i get from the server in a gallery.
i am pasting my code here can anyone tell me what i am doing wrong??

public class HelloAndroid extends Activity {
/** Called when the activity is first created. */

ImageView imView;
public NodeList n_thumbnail;
public NodeList n_gphoto_id;
public NodeList n_album_id;
public ArrayList<String> imgurl = new ArrayList<String>();
public ArrayList<String> photoid = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
r= new Random();
((Gallery) findViewById(R.id.gallery))
.setAdapter(new ImageAdapter(this));
try {
String s=makeHttpRequest("userid", "password");
System.out.println(s);
getPhotos(s,"5435451056290802193");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

private void getPhotos(String auth,String albumid)throws IOException
{
try
{

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
System.out.println("Inside fn************");
String s="http://picasaweb.google.com/data/feed/api/user/userid/albumid/"+albumid+"?fields=entry(media:group(media:thumbnail[@width='72']),gphoto:id,gphoto:albumid)";
URL url = new URL(s);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestProperty(AUTH_HEADER_KEY, String.format(AUTH_HEADER_VALUE_TEMPLATE, auth));
Document doc = db.parse(httpConnection.getInputStream());
n_thumbnail=doc.getElementsByTagName("media:thumbnail");
n_gphoto_id=doc.getElementsByTagName("gphoto:id");
n_album_id=doc.getElementsByTagName("gphoto:albumid");
int i=0;
while(i<n_gphoto_id.getLength())
{
Element element = (Element)n_thumbnail.item(i);
imgurl.add(element.getAttribute("url"));
//imgurl.addAll(collection)
System.out.println(element.getAttribute("url"));
photoid.add(n_gphoto_id.item(i).getFirstChild().getNodeValue());
System.out.println(n_gphoto_id.item(i).getFirstChild().getNodeValue());
System.out.println(n_album_id.item(i).getFirstChild().getNodeValue());
i++;

}


BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
String line;
System.out.println("Inside fn************");
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();





}catch(Exception e){
e.printStackTrace();

}
}

public class ImageAdapter extends BaseAdapter {
/** The parent context */
private Context myContext;
//int i=0;


/** Simple Constructor saving the 'parent' context. */
public ImageAdapter(Context c) { this.myContext = c; }

/** Returns the amount of images we have defined. */
public int getCount() { return imgurl.size();}

/* Use the array-Positions as unique IDs */
public Object getItem(int position) { return position; }
public long getItemId(int position) { return position; }

/** Returns a new ImageView to
* be displayed, depending on
* the position passed. */
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(this.myContext);

try {
System.out.println("Inside image adapter" );
/* Open a new URL and get the InputStream to load data from it. */
for(int j =0;j<imgurl.size();j++){

URL url2= (URL) new URL(imgurl.get(0).toString());
System.out.println(url2.toString());
//HttpURLConnection httpConnection1 = (HttpURLConnection)url2.openConnection();
URLConnection conn = url2.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis =new BufferedInputStream(is);
Bitmap b = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
imView.setImageBitmap(b);
}
} catch (IOException e) {
//i.setImageResource(R.drawable.error);
Log.e("DEBUGTAG", "Remtoe Image Exception", e);
}

/* Image should be scaled as width/height are set. */
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
/* Set the Width/Height of the ImageView. */
i.setLayoutParams(new Gallery.LayoutParams(150, 150));
return i;
}
}


i can see the image url's in the logcat portion however i cannot see anything on the emulator screen.that is the gallery code isn't working.
can anyone please help me out here.its urgent as i need to submit my project at the earliest
thanks in advance
android_anu
Freshman
Freshman
 
Posts: 9
Joined: Fri Feb 12, 2010 6:04 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests