i am using webservice to list detail about local business directory,
here i cant list image from url ,but i got image url which  comes from
web service, now my query is how to list image in list view with
rating bar dynamically from web service.
package xml.parse;



import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;


import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;



import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends ListActivity {
    protected static final int ACTIVITY_CREATE = 0;
    private ArrayList <HashMap<String, Object>> myBooks;
        private static final String BOOKKEY ="lastname";
        private static final String PRICEKEY = "city";
        private static final String Photo = "photo";
        String k;
        Drawable drawable;
        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listplaceholder);
        ListView listView = (ListView)findViewById(R.id.list);
        myBooks = new ArrayList<HashMap<String,Object>>();
        HashMap<String, Object> hm = null;


        String xml = XMLfunctions.getXML("http://122.165.58.219/demo/
finddentist/listdentist.php");
        Document doc = XMLfunctions.XMLfromString(xml);

        int numResults = XMLfunctions.numResults(doc);

        if((numResults <= 0)){
                Toast.makeText(Main.this, "No result found",
Toast.LENGTH_LONG).show();
                finish();
        }

                NodeList nodes = doc.getElementsByTagName("record");

                for (int i = 0; i < nodes.getLength(); i++) {
                          hm = new HashMap<String, Object>();

                        Element e = (Element)nodes.item(i);
                                hm.put(BOOKKEY, XMLfunctions.getValue(e, 
"lastname"));
                        hm.put(PRICEKEY, XMLfunctions.getValue(e,"city"));
                        hm.put(Photo, XMLfunctions.getValue(e,"photo"));
                      myBooks.add(hm);
                      url=(String) hm.get(Photo);
                      Toast.makeText(Main.this,k, Toast.LENGTH_LONG).show();

Drawable drawable = LoadImageFromWebOperations(url);
                imgView.setImageDrawable(drawable);
                      listView.setAdapter(new myListAdapter(myBooks,this));
                      listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                }
    }



        class myListAdapter extends BaseAdapter{

        private ArrayList<HashMap<String, Object>> Books;
        private LayoutInflater mInflater;


                public myListAdapter(ArrayList<HashMap<String, Object>> books,
Context context){


                        Books = books;
                        mInflater = LayoutInflater.from(context);
                }


        @Override
                public int getCount() {
                        // TODO Auto-generated method stub
                        return Books.size();
                }

                @Override
                public Object getItem(int position) {
                        // TODO Auto-generated method stub
                        return Books.get(position);
                }

                @Override
                public long getItemId(int position) {
                        // TODO Auto-generated method stub
                        return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup
parent) {
                        // TODO Auto-generated method stub
                        // A ViewHolder keeps references to children views to 
avoid
unneccessary calls
            // to findViewById() on each row.
                        ViewHolder holder;

                        // When convertView is not null, we can reuse it 
directly, there is
no need
            // to reinflate it. We only inflate a new View when the
convertView supplied
            // by ListView is null
                         if (convertView == null) {
                     convertView = mInflater.inflate(R.layout.listbox, null);
                     // Creates a ViewHolder and store references to the two
children views
                     // we want to bind data to.
                     holder = new ViewHolder();
                     holder.v = (TextView)
convertView.findViewById(R.id.text1);
                     holder.v1 = (TextView)
convertView.findViewById(R.id.text2);
                    // holder.icon =(ImageView)findViewById(R.id.img);

                      convertView.setTag(holder);

                         }else {
                                 // Get the ViewHolder back to get fast access 
to the TextView
                     // and the ImageView.
                                 holder = (ViewHolder) convertView.getTag();
                         }
                                // Bind the data with the holder.

                                holder.v.setText((String) 
Books.get(position).get(BOOKKEY));

                                holder.v1.setText((String) 
Books.get(position).get(Photo));
                                //holder.icon.setImageDrawable(drawable);
                        //
holder.icon.setImageResource((Integer)Books.get(position).get(drawable));

                                return convertView;
                }
                private Drawable LoadImageFromWebOperations(String url)
            {
            try
            {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
            }catch (Exception e) {
            System.out.println("Exc="+e);
            return null;
            }
            }

                 class ViewHolder {
                        TextView v;
                TextView v1;
                ImageView icon;
        }

    }


}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to