0

我有一个数组,如下所示,我手动记下照片链接,我有一个问题如何将数组转换为 for 循环,以便在我更改 SQL 中的链接后图像将自动更新。

public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);

            i.setImageResource(mImageIds[position]);                             

            return i;
        }        

        private Integer[] mImageIds = {
                R.drawable.ctr,
                R.drawable.fb,
                R.drawable.games,
                R.drawable.ic_launcher,
                R.drawable.ctr,
                R.drawable.ctr,
                R.drawable.ctr,
                R.drawable.ctr,
                R.drawable.ea,
                R.drawable.fb,
                R.drawable.ctr
        };

更新我想我几乎解决了:我把这些放在 getView()

public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(mContext);

        final String SOAP_ACTION = "http://tempuri.org/findAppsByID";
        final String METHOD_NAME = "findAppsByID";
        final String NAMESPACE = "http://tempuri.org/";
        final String URL = "http://domainURL.com/appsFeaturedWS.asmx";

        SoapObject Request = new SoapObject (NAMESPACE, METHOD_NAME);
        Request.addProperty("ID", position+1);
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);

        AndroidHttpTransport aht = new AndroidHttpTransport(URL);

        try
        {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapObject resultString = (SoapObject) soapEnvelope.getResponse();

            final String[] strLogo = new String[resultString.getPropertyCount()];

            for(int j =0; j<resultString.getPropertyCount(); j++)
            {
                SoapObject array = (SoapObject) resultString .getProperty(j);
                strLogo[j] = array.getProperty(5).toString();   //get logo

                i.setImageResource(Integer.parseInt(strLogo[j]));
            }
        }

        catch(Exception e){
        }                    

        return i;
    }

但我的屏幕只是显示空白......有什么问题吗?

4

2 回答 2

0

检查 LazyAdapter 示例的链接LazyAdapter这对于从网络获取图像以显示在gridview、listview 或galary 视图中很有用检查它

于 2012-06-22T04:55:07.557 回答
-1

mImageIds 定义全局

public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);
            for(int i=0;i<mImageIds.length;i++{
            if(i==position){ 
             i.setImageResource(mImageIds[position]);                             
             }
            }
            return i;
        }        

        private Integer[] mImageIds = {
                R.drawable.ctr,
                R.drawable.fb,
                R.drawable.games,
                R.drawable.ic_launcher,
                R.drawable.ctr,
                R.drawable.ctr,
                R.drawable.ctr,
                R.drawable.ctr,
                R.drawable.ea,
                R.drawable.fb,
                R.drawable.ctr
        };
于 2012-06-21T10:48:44.250 回答