1

I'm new to android domain..

I'm working with small app..

What i need is ??

I have videos urls and image urls in a array list,which retrive from database as json object and stored in separate array. I want this array list of images should show in listview with text.

How to implement this?? please help me..

I have went through google but still i didn't clear example.. Please any one help me..

Thanks a lot in advance...

  public class act extends Activity {
/** Called when the activity is first created. */
static  String uri1="http://i3.ytimg.com/vi/bQaWsVQSLdY/default.jpg";
static String uri2="http://i4.ytimg.com/vi/cJQCniWQdno/mqdefault.jpg";
static String uri3="http://i1.ytimg.com/vi/D8dA4pE5hEY/mqdefault.jpg";
public static String[] urls={uri1,uri2,uri3};
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    GridView grd=(GridView)findViewById(R.id.gridView1);
    grd.setAdapter(new ImageAdapter(this));
    grd.setOnItemClickListener(new OnItemClickListener()
    {
    public void onItemClick(AdapterView<?> parent,View v,int pos,long id)
    {
        Toast.makeText(getBaseContext(),"pic"+(pos+1)+"select ",Toast.LENGTH_SHORT).show();
    }
    });
}
public class ImageAdapter extends BaseAdapter
{
    private Context context;
    private int itemBackground;
    ImageAdapter(Context c)
    {
    context=c;
    TypedArray a=obtainStyledAttributes(R.styleable.Gallery1);
    itemBackground=a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground,0);
    a.recycle();
    }
    public int getCount()
    {
        return urls.length;
    }
    public Object getItem(int pos)
    {
        return pos;
    }
    public long getItemId(int pos)
    {
        return pos;
    }
    public View getView(int pos,View cv,ViewGroup vg)
    {
        ImageView imageview=new ImageView(context);
        imageview.setImageResource(urls[pos]);
        imageview.setScaleType(ImageView.ScaleType.FIT_XY);
        imageview.setLayoutParams(new Gallery.LayoutParams(150,120));
        imageview.setBackgroundResource(itemBackground);
        return imageview;
    }
}

}

I try like this..i can't able to get the image...

Make it Simple
  • 1,832
  • 5
  • 32
  • 57
  • is this a different question alltogether with bounty? http://stackoverflow.com/questions/16212883/images-url-are-not-displaying-in-grid – Nezam Apr 30 '13 at 08:15

2 Answers2

1

you can't set it directly as you are trying to do, you will first need to download the image, store the bitmap, and only then apply the image to you ImageView.

check this question:

How to set image button resource from web url in Android?

this solution is good as well:

How to load an ImageView by URL in Android?

Community
  • 1
  • 1
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • edit my code and you post as answer with download the image..plz im new to android..If u edit i will learn it...help me.. – Make it Simple Apr 30 '13 at 07:25
  • 1
    @OneManArmy, I'm not going to write your code for you for two reasons: 1. I don't have time for it. 2. You will learn nothing if I will do so. And you misunderstanding the purpose of this site. We here to help you, not to do your work for you. If you have another problem now update you question with the new code or open a new more relevant question. – Emil Adz Apr 30 '13 at 08:26
0

If the requirement is of showing the imageview and textview in list row then try the concept of universal loader. Link:

https://github.com/nostra13/Android-Universal-Image-Loader

deepak825
  • 432
  • 2
  • 8