2013-04-30 139 views
1

圖像URL我是新來的Android域..顯示在列表視圖

我與小應用程序的工作..

我需要的是?

我有一個數組列表中的視頻網址和圖像網址,它從數據庫中作爲json對象進行檢索並存儲在單獨的數組中。我想這個數組列表的圖像應該顯示在列表視圖與文本。

如何實現?請幫助我..

我已經通過谷歌去了,但我仍然沒有明顯的例子。請任何一個幫助我..

感謝很多提前...

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; 
    } 
} 

}

我嘗試像this..i不能抽到圖像...

+0

這是一個不同的問題與產品總數賞​​金? http://stackoverflow.com/questions/16212883/images-url-are-not-displaying-in-grid – Nezam 2013-04-30 08:15:47

回答

1

ÿ ou無法直接設置,因爲您正在嘗試做,您首先需要下載圖像, 存儲位圖,然後纔將圖像應用於您ImageView

檢查這個問題:

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

這個解決方案一樣好:

How to load an ImageView by URL in Android?

+0

編輯我的代碼,你發佈的答案與下載image..plz即時新的android..If ü編輯我會學習它...幫助我.. – 2013-04-30 07:25:17

+0

幫我... PLZ我無法使用我的代碼中的代碼.. – 2013-04-30 07:39:19

+1

@OneManArmy,我不會爲你寫代碼兩個原因:1.我沒時間了。 2.如果我願意,你將不會學到任何東西。你誤解了這個網站的目的。我們在這裏幫助你,而不是爲你做你的工作。如果您現在有其他問題,請使用新代碼更新您的問題,或者打開一個更相關的新問題。 – 2013-04-30 08:26:28