Beiträge von k3vin

    Ich möchte, dass 200 Bilder von einer Webseite in einer ListView verteilt werden. Also dass die ListView dann auch 200 Reihen lang ist und in jeder ein Bild erscheint.
    Bisher habe ich nur die 200 Reihen der ListView und jeweils in jeder Reihe die Überschrift und die Internetadresse des Bildes.



    Hier ist mein CustomAdapter:


    Code
    [/font][/color][color=#333333][font='verdana, geneva, lucida, lucida grande, arial, helvetica, sans-serif']public class CustomAdapter extends BaseAdapter implements View.OnClickListener {/*********** Declare Used Variables *********/private Activity activity;private ArrayList data;private static LayoutInflater inflater=null;public Resources res;ListModel tempValues=null;int i=0;/************* CustomAdapter Constructor *****************/public CustomAdapter(Activity a, ArrayList d,Resources resLocal) {/********** Take passed values **********/activity = a;data=d;res = resLocal;/*********** Layout inflator to call external xml layout () ***********/inflater = ( LayoutInflater )activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);}/******** What is the size of Passed Arraylist Size ************/public int getCount() {if(data.size()<=0)return 1;return data.size();}public Object getItem(int position) {return position;}public long getItemId(int position) {return position;}/********* Create a holder Class to contain inflated xml file elements *********/public static class ViewHolder{public TextView text;public TextView text1;public TextView textWide;public ImageView image;}/****** Depends upon data size called for each row , Create each ListView row *****/public View getView(int position, View convertView, ViewGroup parent) {View vi = convertView;ViewHolder holder;if(convertView==null){/****** Inflate tabitem.xml file for each row ( Defined below ) *******/vi = inflater.inflate(R.layout.tabitem, null);/****** View Holder Object to contain tabitem.xml file elements ******/holder = new ViewHolder();holder.text = (TextView) vi.findViewById(R.id.text);holder.text1=(TextView)vi.findViewById(R.id.text1);holder.image=(ImageView)vi.findViewById(R.id.image);/************ Set holder with LayoutInflater ************/vi.setTag( holder );}elseholder=(ViewHolder)vi.getTag();if(data.size()<=0){holder.text.setText("No Data");}else{/***** Get each Model object from Arraylist ********/tempValues=null;tempValues = ( ListModel ) data.get(position);/************ Set Model values in Holder elements ***********/holder.text.setText(tempValues.getCompanyName());holder.text1.setText( tempValues.getUrl() );holder.image.setImageResource(res.getIdentifier("com.androidexample.customlistview:drawable/"+tempValues.getImage(),null,null));/******** Set Item Click Listner for LayoutInflater for each row *******/vi.setOnClickListener(new OnItemClickListener( position ));}return vi;}@Overridepublic void onClick(View v) {Log.v("CustomAdapter", "=====Row button clicked=====");}/********* Called when Item click in ListView ************/private class OnItemClickListener implements View.OnClickListener{private int mPosition;OnItemClickListener(int position){mPosition = position;}@Overridepublic void onClick(View arg0) {CustomListView sct = (CustomListView)activity;/**** Call onItemClick Method inside CustomListViewAndroidExample Class ( See Below )****/sct.onItemClick(mPosition);}}[/font][/color][color=#333333][font='verdana, geneva, lucida, lucida grande, arial, helvetica, sans-serif']



    Und hier sind meine eigenen Codes:



    Code
    [/font][/color][color=#333333][font='verdana, geneva, lucida, lucida grande, arial, helvetica, sans-serif']public static Bitmap getBitmapFromURL(String src) {try {URL url = new URL(src);return BitmapFactory.decodeStream(url.openConnection().getInputStream());}catch(Exception e){e.printStackTrace();}return null;}public String getPictureName (int i){String in = ""+i+"";if(in.length() == 1){return "000"+in;}else if(in.length() == 2){return "00"+in;}else if(in.length() == 3){return "0"+in;}else{return in;}}for(int i = 1; i <= 200; i++){final int ii = i;final ImageView imageView = new ImageView(CustomListView.this);RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);//linearLayout.addView(imageView,lp);Thread thread = new Thread(){@Overridepublic void run(){final Bitmap bm = getBitmapFromURL("http://myURL.de/picture_"+getPictureName(ii)+".jpg");runOnUiThread(new Runnable() {@Overridepublic void run() {if(bm !=null){imageView.setImageBitmap(bm);}else {//linearLayout.removeView(imageView);}}});}};thread.start ();}[/font][/color][color=#333333][font='verdana, geneva, lucida, lucida grande, arial, helvetica, sans-serif']



    Aber ich weiß jetzt nicht genau wo ich meinen Code einsetzen soll und im Internet fand ich auch nichts nützliches, wie man das macht und wohin der Code, der sagt, woher die Bilder geholt werden sollen, eingefügt werden soll ...
    Hoffe es kann mir jemand helfen ..
    Lg[/font][/color]