发布图像数组有问题

时间:2017-12-01 08:52:59

标签: objective-c

我从图库中选择多个图像我必须将这些图像发布到网络服务但我发布的问题只发布一个图像我发布任何一个帮助我解决这个问题 在此先感谢....

这是我的代码

// GetHttpResponse  class on PegawaiActivity  
    public class GetHttpResponse extends AsyncTask<Void, Void, Void>
    {
        public Context context;

        String JSonResult;

        List<Member> studentList;
private ListView listView;

        public GetHttpResponse(Context context)
        {
            this.context = context;
        }

public void setListView(ListView listView){
      this.listView = listView;
}

        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... arg0)
        {
            // Passing HTTP URL to HttpServicesClass Class.
            HttpServicesClass httpServicesClass = new HttpServicesClass(HttpUrl);
            try
            {
                httpServicesClass.ExecutePostRequest();

                if(httpServicesClass.getResponseCode() == 200)
                {
                    JSonResult = httpServicesClass.getResponse();

                    if(JSonResult != null)
                    {
                        JSONArray jsonArray = null;

                        try {
                            jsonArray = new JSONArray(JSonResult);

                            JSONObject jsonObject;
                            Member member;
                            studentList = new ArrayList<Member>();

                            for(int i=0; i<jsonArray.length(); i++)
                            {
                                member = new Member();
                                jsonObject = jsonArray.getJSONObject(i);

                                // Adding Student Id TO IdList Array.
                                IdList.add(jsonObject.getString("id").toString());
                                //Adding Student Name.
                                member.nama = jsonObject.getString("nama").toString();
                                member.nrp = jsonObject.getString("nrp").toString();
                                studentList.add(member);

                            }
                        }
                        catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
                else
                {
                    Toast.makeText(context, httpServicesClass.getErrorMessage(), Toast.LENGTH_SHORT).show();
                }
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result)

        {
            progressBar.setVisibility(View.GONE);
            StudentListView.setVisibility(View.VISIBLE);

            if(studentList != null) {
                ListAdapterClass adapter = new ListAdapterClass(studentList, context);
                listView.setAdapter(adapter);
            }else
            {
                Toast.makeText(context, "Tidak ada data ditampilkan", Toast.LENGTH_SHORT).show();
            }

        }
    }

这里只有单个图片发布到服务器我需要发送图像数组...

1 个答案:

答案 0 :(得分:0)

如果您不希望应用程序冻结,则必须在后台队列中逐个发送。

请按以下步骤操作: 1.调用上传阵列第一张图像的功能。

null

2.当您获得第一张图片上传的响应时,再次调用上传功能,但这次使用增加的数组索引。

[self uploadingMethod];

-(void)uploadingMethod
    {
        //Hit the uploading service here.

        [self uploadtask:0]; //0 being the index of the array

    }

-(void)uploadtask:(int*)IndexNumber
{
  //Upload the image in background thread.
}