package test.Test; import android.app.Activity; import android.app.SearchManager.OnCancelListener; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.Gallery; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ScrollView; import android.widget.Toast; import java.net.*; import java.io.*;
import org.apache.http.util.ByteArrayBuffer; public class test extends Activity implements OnClickListener { /** Called when the activity is first created. */ ImageView i[] = new ImageView[10]; int j; String names[] = new String[10]; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout m = new LinearLayout(this); for(j=0;j<10;j++) { //DownloadFromUrl("google.jpg","test.png"); i[j] = new ImageView(this); //i[j] = new ImageView(this); i[j].setImageResource(R.drawable.icon); i[j].setAdjustViewBounds(true); i[j].setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); m.addView(i[j]); names[j]=j+""; i[j].setOnClickListener((OnClickListener) this); } //i[1].setImageResource(R.drawable.icon); //i[1].setAdjustViewBounds(true); //i[1].setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); //m.addView(i[1]); //i[1].setOnClickListener((OnClickListener) this); setContentView(m); } public void onClick(View v) { int j; String s = new String(); for(j=0;j<10;j++) { if(v == i[j]) { Intent intent=new Intent(test.this,next.class); intent.putExtra("Name",names[j]); final int result=1; startActivityForResult(intent,result); //s=j+" rajeev"; //Context context = getApplicationContext(); //Toast.makeText(context,s, Toast.LENGTH_SHORT).show(); //break; } } /*if(v == i[1]) { Context context = getApplicationContext(); Toast.makeText(context,"Second", Toast.LENGTH_SHORT).show(); }*/ } public void DownloadFromUrl(String imageURL, String fileName) { //this is the downloader method try { URL url = new URL("http://web.iiit.ac.in/ ~rajeshuni.rajeev/orange/" + imageURL); //you can write here any link File file = new File("/data/data/ test.Test/"+fileName); long startTime = System.currentTimeMillis(); Log.d("ImageManager", "download begining"); Log.d("ImageManager", "download url:" + url); Log.d("ImageManager", "downloaded file name:" + fileName); /* Open a connection to that URL. */ URLConnection ucon = url.openConnection(); /* * Define InputStreams to read from the URLConnection. */ InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); /* * Read bytes to the Buffer until there is nothing more to read(-1). */ ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.close(); Log.d("ImageManager", "download ready in" + ((System.currentTimeMillis() - startTime) / 1000) + " sec"); } catch (IOException e) { Context context = getApplicationContext(); Toast.makeText(context,"internet problem", Toast.LENGTH_SHORT).show(); } } } There is no XML file for this activity.How to add scrolling option here. Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en