上传图片显示不但是别人就是显示上传图片、不但是

2023-09-03 21:30:47 作者:锦书念伊安

我面临着一些奇怪的,我可以看到我在链接我上传的图像但它没有显示在应用程序。但如果我进入另一个图像链接其在应用程序显示。是什么原因?任何人都可以帮忙吗?

在main_actvity

  //下载数据不同步
    公共类AsyncHttpTask扩展的AsyncTask<字符串,太虚,整数GT; {

        @覆盖
        保护整数doInBackground(字符串... PARAMS){
            整数结果为0;
            尝试 {
                //创建的Apache的HttpClient
                HttpClient的HttpClient的=新DefaultHttpClient();
                HTT presponse HTT presponse = httpclient.execute(新HTTPGET(PARAMS [0]));
                INT状态code = HTT presponse.getStatusLine()的getStatus code()。

                // 200重新presents HTTP OK
                如果(状态code == 200){
                    字符串响应= streamToString(HTT presponse.getEntity()的getContent());
                    parseResult(响应);
                    结果= 1; //成功
                } 其他 {
                    结果= 0; //失败
                }
            }赶上(例外五){
                Log.d(TAG,e.getLocalizedMessage());
            }
            返回结果;
        }

        @覆盖
        保护无效onPostExecute(整数结果){
            //下载完成。让我们更新UI
            如果(结果== 1){
                mGridAdapter.setGridData(mGridImages);
            } 其他 {
                Toast.makeText(MainActivity.this!没有找到连接,请检查您的连接,Toast.LENGTH_SHORT).show();
            }
            mProgressBar.setVisibility(View.GONE);
        }
    }

    字符串streamToString(InputStream的流)抛出IOException异常{
        BufferedReader中的BufferedReader =新的BufferedReader(新的InputStreamReader(流));
        串线;
        字符串结果=;
        而((行= bufferedReader.readLine())!= NULL){
            结果+ =行;
        }

        //关闭流
        如果(NULL!=流){
            stream.close();
        }
        返回结果;
    }

    / **
     *解析提要结果,并获得名单
     * @参数结果
     * /
    私人无效parseResult(字符串结果){
        尝试 {

            JSONObject的响应=新的JSONObject的(结果);
            JSONArray帖= response.optJSONArray(结果);
            GridImages项目;
            的for(int i = 0; I< posts.length();我++){
                JSONObject的帖子= posts.optJSONObject(我);
                字符串标题= post.optString(姓名);
                字符串图像= post.optString(路径);
                项目=新GridImages();
                item.Settitle(职称);
                item.Setimage(图像);

                mGridImages.add(项目);
            }
        }赶上(JSONException E){
            e.printStackTrace();
        }
    }



   //用于调用上传图片的方法
        公共无效openGallery(){

            意向意图=新的意图();
            intent.setType(图像/ *);
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(意向,选择图片),1);

           }
         @覆盖
         保护无效onActivityResult(INT申请code,INT结果code,意图数据){
             super.onActivityResult(要求code,因此code,数据);

              如果(要求code == 1安培;&安培;结果code == RESULT_OK和放大器;&放大器;数据= NULL和放大器;!&安培;!data.getData()= NULL){

                  //文件名
                     乌里selectedImage = data.getData();

                     意图I =新的意图(这一点,
                              AddImage.class);
                    i.putExtra(的ImagePath,selectedImage.toString());
                    startActivity(ⅰ);
              }
         }

    //操作栏菜单的设计
    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
         MenuInflater充气= getMenuInflater();
            inflater.inflate(R.menu.activity_main_actions,菜单);

        返回super.onCreateOptionsMenu(菜单);
    }

       公共布尔onOptionsItemSelected(菜单项项)
       {
          super.onOptionsItemSelected(项目);

     开关(item.getItemId()){

     案例R.id.ic_action_person:
         Toast.makeText(这一点,创建一个新帐户,请,Toast.LENGTH_SHORT).show();
           意向意图=新的意图(这一点,Register.class);
             startActivity(意向);
         返回true;

     案例R.id.ic_action_search:

         Toast.makeText(这一点,搜索新形象,Toast.LENGTH_SHORT).show();
         意图ISEARCH =新的意图(这一点,Search.class);
            startActivity(ISEARCH);
     返回true;

     案例R.id.ic_action_picture:
         Toast.makeText(这一点,搜索新照片,Toast.LENGTH_SHORT).show();
         意图iphotos =新的意图(这一点,Display.class);
         startActivity(iphotos);
         返回true;

     案例R.id.ic_add_photo:
         Toast.makeText(这一点,搜索新照片,Toast.LENGTH_SHORT).show();

          openGallery();

         返回true;
     }
        返回true;
       }
   }
 

addimage.java我在哪里上传图片

 公共无效的onCreate(包冰柱){
            super.onCreate(冰柱);
            的setContentView(R.layout.main);

            EditText上captionetxt =(EditText上)findViewById(R.id.caption);
            。标题= captionetxt.getText()的toString();
            //微调
            微调下拉=(微调)findViewById(R.id.spinner1);
            的String []项目=新的String [] {黎巴嫩的笑话,学生恶搞,行情};
            ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(这一点,android.R.layout.simple_spinner_item,项目);
            dropdown.setAdapter(适配器);
             。categorie = dropdown.getSelectedItem()的toString();
            ImageView的=(ImageView的)findViewById(R.id.imageView);
                }
        公共无效的onclick(查看视图)
        {
            Toast.makeText(AddImage.this上传图片,Toast.LENGTH_LONG).show();
            上传();

              意图I =新的意图(这一点,
                        MainActivity.class);
              startActivity(ⅰ);
        }
        公共无效的上传()
        {
              日历thisCal = Calendar.getInstance();
              thisCal.getTimeInMillis();
                意向意图= getIntent();
                串selectedImage = intent.getStringExtra(的ImagePath);
                乌里=了fileURI Uri.parse(selectedImage);

            的System.out.println(了fileURI);
            的InputStream的ImageStream = NULL;
            尝试 {
                的ImageStream = getContentResolver()openInputStream(了fileURI)。
            }赶上(FileNotFoundException异常E){
                e.printStackTrace();
            }

            BMP位= BitmapFactory.de codeStream(的ImageStream);

            ByteArrayOutputStream流=新ByteArrayOutputStream();
            bmp.com preSS(Bitmap.Com pressFormat.JPEG,30,流);


            字节[]的字节数组= stream.toByteArray();
            点阵位图= BitmapFactory.de codeByteArray(字节数组,0,byteArray.length);
            imageview.setImageBitmap(位);
            INT宽度= bitmap.getWidth();
            INT高= bitmap.getHeight();
            的System.out.println(宽);
            的System.out.println(高度);


            getResizedBitmap(位图,200);
            尝试 {
                stream.close();
                流= NULL;
            }赶上(IOException异常E){

                e.printStackTrace();
            }

            字符串image_str = Base64.en codeBytes(字节阵列);
            最后的ArrayList<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePair>();
            nameValuePairs.add(新BasicNameValuePair(形象,image_str));
            nameValuePairs.add(新BasicNameValuePair(标题,字幕));
            nameValuePairs.add(新BasicNameValuePair(姓名,济));
            nameValuePairs.add(新BasicNameValuePair(categorie,categorie));
             线程t =新主题(新的Runnable(){

            @覆盖
            公共无效的run(){
                  尝试{

                         HttpClient的HttpClient的=新DefaultHttpClient();
                         HttpPost httppost =新HttpPost(http://justedhak.comlu.com/images/upload_image.php);
                         httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));
                         HTT presponse响应= httpclient.execute(httppost);
                         最后弦乐the_string_response = convertResponseToString(响应);
                         runOnUiThread(新的Runnable(){

                                @覆盖
                                公共无效的run(){
                                    Toast.makeText(AddImage.this,响应+ the_string_response,Toast.LENGTH_LONG).show();
                                }
                            });

                     }赶上(最终例外五){
                          runOnUiThread(新的Runnable(){

                            @覆盖
                            公共无效的run(){
                                Toast.makeText(AddImage.this,ERROR+ e.getMessage(),Toast.LENGTH_LONG).show();
                            }
                        });
                           的System.out.println(在HTTP连接错误+ e.toString());
                     }
            }
        });
         t.start();
        }

        公共字符串convertResponseToString(Htt的presponse响应)抛出IllegalStateException异常,IOException异常{

             字符串资源=;
             StringBuffer的缓冲区=新的StringBuffer();
             的InputStream = response.getEntity()的getContent()。
             最终诠释CONTENTLENGTH =(int)的response.getEntity()getContentLength()。 //获取内容长度... ..
              runOnUiThread(新的Runnable(){

            @覆盖
            公共无效的run(){
                Toast.makeText(AddImage.thisCONTENTLENGTH:+ CONTENTLENGTH,Toast.LENGTH_LONG).show();
            }
        });

             如果(CONTENTLENGTH℃,){
             }
             其他{
                    byte []的数据=新的字节[512];
                    INT的len = 0;
                    尝试
                    {
                        而(-1!=(LEN = inputStream.read(数据)))
                        {
                            buffer.append(新的字符串(data,0,len个)); //转换为字符串,并追加到StringBuffer的... ..
                        }
                    }
                    赶上(IOException异常E)
                    {
                        e.printStackTrace();
                    }
                    尝试
                    {
                        inputStream.close(); //关闭流......
                    }
                    赶上(IOException异常E)
                    {
                        e.printStackTrace();
                    }
                    RES = buffer.toString(); //转换StringBuffer来串... ..

                    runOnUiThread(新的Runnable(){

                    @覆盖
                    公共无效的run(){
                       Toast.makeText(AddImage.this,结果:水库,Toast.LENGTH_LONG).show();
                    }
                });
                    //System.out.println("Response =>中+ EntityUtils.toString(response.getEntity()));
             }
             返回水库;
        }

        公共位图getResizedBitmap(位图图像​​,诠释MAXSIZE){
            INT宽度= image.getWidth();
            INT高= image.getHeight();

            浮动bitmapRatio =(浮点)宽/(浮动)的高度;
            如果(bitmapRatio大于0){
                宽度= MAXSIZE;
                身高=(INT)(宽/ bitmapRatio);
            } 其他 {
                身高= MAXSIZE;
                宽度=(INT)(高* bitmapRatio);
            }
            返回Bitmap.createScaledBitmap(图像,宽度,高度,真);
    }



}
 

主要XML

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的EditText
机器人:ID =@ + ID /标题
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:以下属性来=10dp
机器人:提示=插入题注/>
 <微调
机器人:ID =@ + ID / spinner1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID /标题
机器人:以下属性来=10dp
机器人:背景=@机器人:可绘制/ btn_dropdown
机器人:spinnerMode =下拉列表中/>

<按钮
机器人:ID =@ + ID / BTN1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / spinner1
机器人:layout_weight =1
机器人:文本=邮报
机器人:的onClick =的onclick/>


< ImageView的
    机器人:ID =@ + ID / ImageView的
       机器人:layout_width =300dp
       机器人:layout_height =300dp
       机器人:layout_below =@ + ID / BTN1
       机器人:以下属性来=20dp/>

< / RelativeLayout的>
 
为什么我空间背景图片别人看到的都是已删除,然后我上传到了相册 可是照片变小了,不能全屏了 怎么办啊

mgridadapter

 公共类GridImageMainAdapter扩展ArrayAdapter< GridImages> {

    私人语境mContext;
    私人诠释layoutResourceId;
    私人的ArrayList< GridImages> mGridImages =新的ArrayList< GridImages>();

    公共GridImageMainAdapter(上下文mContext,INT layoutResourceId,ArrayList的< GridImages> mGridImages){
        超(mContext,layoutResourceId,mGridImages);
        this.layoutResourceId = layoutResourceId;
        this.mContext = mContext;
        this.mGridImages = mGridImages;
    }


    / **
     *更新网格数据,并刷新网格项目。
     * @参数mGridData
     * /
    公共无效setGridData(ArrayList中< GridImages> mGridImages){
        this.mGridImages = mGridImages;
        notifyDataSetChanged();
    }

    @覆盖
    公共查看getView(INT位置,查看convertView,ViewGroup中父){
        查看排= convertView;
        ViewHolder持有人;
        如果(BuildConfig.DEBUG){
            Picasso.with(mContext).setIndicatorsEnabled(真正的);
            Picasso.with(mContext).setLoggingEnabled(真正的);
        }
        如果(行== NULL){
            LayoutInflater充气=((活动)mContext).getLayoutInflater();
            行= inflater.inflate(layoutResourceId,父母,假);
            持有人=新ViewHolder();
            holder.titleTextView =(TextView中)row.findViewById(R.id.grid_item_title);
            holder.imageView =(ImageView的)row.findViewById(R.id.grid_item_image);
            row.setTag(保持器);
        } 其他 {
            支架=(ViewHolder)row.getTag();
        }

        GridImages项目= mGridImages.get(位置);
        holder.titleTextView.setText(Html.fromHtml(item.Gettitle()));

        毕加索。
        与(mContext)。
        负载(item.Getimage())
        .placeholder(R.drawable.ic_launcher)//也可以是可拉伸
         .fit()//稍后会解释
        。走进(holder.imageView);

        返回行;
    }

    静态类ViewHolder {
        TextView的titleTextView;
        ImageView的ImageView的;
    }
}
 

解决方案

添加 mGridAdapter.notifyDatasetChange()后修改gridview的数据。

I am facing something weird , I can see the image that I am uploading in the link however it is not showing in the app. but If I enter another image link its displaying in the app. what is the cause ? anyone can help ?

the main_actvity

    //Downloading data asynchronously
    public class AsyncHttpTask extends AsyncTask<String, Void, Integer> {

        @Override
        protected Integer doInBackground(String... params) {
            Integer result = 0;
            try {
                // Create Apache HttpClient
                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse httpResponse = httpclient.execute(new HttpGet(params[0]));
                int statusCode = httpResponse.getStatusLine().getStatusCode();

                // 200 represents HTTP OK
                if (statusCode == 200) {
                    String response = streamToString(httpResponse.getEntity().getContent());
                    parseResult(response);
                    result = 1; // Successful
                } else {
                    result = 0; //"Failed
                }
            } catch (Exception e) {
                Log.d(TAG, e.getLocalizedMessage());
            }
            return result;
        }

        @Override
        protected void onPostExecute(Integer result) {
            // Download complete. Let us update UI
            if (result == 1) {
                mGridAdapter.setGridData(mGridImages);
            } else {
                Toast.makeText(MainActivity.this, "No Connection found,Check your Connection!", Toast.LENGTH_SHORT).show();
            }
            mProgressBar.setVisibility(View.GONE);
        }
    }

    String streamToString(InputStream stream) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
        String line;
        String result = "";
        while ((line = bufferedReader.readLine()) != null) {
            result += line;
        }

        // Close stream
        if (null != stream) {
            stream.close();
        }
        return result;
    }

    /**
     * Parsing the feed results and get the list
     * @param result
     */
    private void parseResult(String result) {
        try {

            JSONObject response = new JSONObject(result);
            JSONArray posts = response.optJSONArray("result");
            GridImages item;
            for (int i = 0; i < posts.length(); i++) {
                JSONObject post = posts.optJSONObject(i);
                String title = post.optString("name");
                String image=post.optString("path");
                item = new GridImages();
                item.Settitle(title);
                item.Setimage(image);

                mGridImages.add(item);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }



   // The method that invoke of uploading images
        public   void openGallery() {

            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);

           }
         @Override
         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
             super.onActivityResult(requestCode, resultCode, data);

              if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {

                  //file name
                     Uri selectedImage = data.getData();

                     Intent i = new Intent(this,
                              AddImage.class);
                    i.putExtra("imagePath", selectedImage.toString());
                    startActivity(i);                  
              }
         }

    // the design of the action bar menu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
         MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.activity_main_actions, menu);

        return super.onCreateOptionsMenu(menu);
    }

       public boolean onOptionsItemSelected(MenuItem item) 
       { 
          super.onOptionsItemSelected(item); 

     switch (item.getItemId()){

     case R.id.ic_action_person:
         Toast.makeText(this, "Create a new account please", Toast.LENGTH_SHORT).show();
           Intent intent = new Intent(this, Register.class);
             startActivity(intent);
         return true;

     case R.id.ic_action_search:

         Toast.makeText(this, "Search for new images", Toast.LENGTH_SHORT).show();
         Intent  isearch= new Intent(this,Search.class);
            startActivity(isearch);
     return true;

     case R.id.ic_action_picture:
         Toast.makeText(this, "Search for new photos", Toast.LENGTH_SHORT).show();
         Intent  iphotos= new Intent(this,Display.class);
         startActivity(iphotos);
         return true;

     case R.id.ic_add_photo:
         Toast.makeText(this, "Search for new photos", Toast.LENGTH_SHORT).show();

          openGallery();

         return true;
     }
        return true;
       } 
   }

addimage.java where I am uploading images

    public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.main);

            EditText captionetxt = (EditText) findViewById(R.id.caption);
            caption = captionetxt.getText().toString();
            //spinner
            Spinner dropdown = (Spinner)findViewById(R.id.spinner1);
            String[] items = new String[]{"Lebanese jokes", "Student Jokes", "Quotes"};
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items);
            dropdown.setAdapter(adapter);
             categorie = dropdown.getSelectedItem().toString(); 
            imageview = (ImageView) findViewById(R.id.imageView);           
                }
        public void onclick(View view)
        {
            Toast.makeText(AddImage.this, "Uploading Image", Toast.LENGTH_LONG).show();                         
            upload();

              Intent i = new Intent(this,
                        MainActivity.class);
              startActivity(i);
        }
        public void upload()
        {
              Calendar thisCal = Calendar.getInstance();
              thisCal.getTimeInMillis();
                Intent intent = getIntent();
                String selectedImage= intent.getStringExtra("imagePath");
                Uri fileUri = Uri.parse(selectedImage);

            System.out.println(fileUri);
            InputStream imageStream = null;
            try {
                imageStream = getContentResolver().openInputStream(fileUri);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            Bitmap bmp = BitmapFactory.decodeStream(imageStream);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.JPEG, 30, stream);


            byte[] byteArray = stream.toByteArray();
            Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
            imageview.setImageBitmap(bitmap);
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            System.out.println(width);
            System.out.println(height);


            getResizedBitmap( bitmap, 200);
            try {
                stream.close();
                stream = null;
            } catch (IOException e) {

                e.printStackTrace();
            }

            String image_str = Base64.encodeBytes(byteArray);
            final ArrayList<NameValuePair> nameValuePairs = new  ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("image",image_str));
            nameValuePairs.add(new BasicNameValuePair("caption",caption));
            nameValuePairs.add(new BasicNameValuePair("name","je"));
            nameValuePairs.add(new BasicNameValuePair("categorie",categorie));
             Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                  try{

                         HttpClient httpclient = new DefaultHttpClient();
                         HttpPost httppost = new HttpPost("http://justedhak.comlu.com/images/upload_image.php");
                         httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                         HttpResponse response = httpclient.execute(httppost);
                         final String the_string_response = convertResponseToString(response);
                         runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Toast.makeText(AddImage.this, "Response " + the_string_response, Toast.LENGTH_LONG).show();                         
                                }
                            });

                     }catch(final Exception e){
                          runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(AddImage.this, "ERROR " + e.getMessage(), Toast.LENGTH_LONG).show();                             
                            }
                        });
                           System.out.println("Error in http connection "+e.toString());
                     }  
            }
        });
         t.start();
        }

        public String convertResponseToString(HttpResponse response) throws IllegalStateException, IOException{

             String res = "";
             StringBuffer buffer = new StringBuffer();
             inputStream = response.getEntity().getContent();
             final int contentLength = (int) response.getEntity().getContentLength(); //getting content length…..
              runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(AddImage.this, "contentLength : " + contentLength, Toast.LENGTH_LONG).show();                        
            }
        });

             if (contentLength < 0){
             }
             else{
                    byte[] data = new byte[512];
                    int len = 0;
                    try
                    {
                        while (-1 != (len = inputStream.read(data)) )
                        {
                            buffer.append(new String(data, 0, len)); //converting to string and appending  to stringbuffer…..
                        }
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                    try
                    {
                        inputStream.close(); // closing the stream…..
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                    res = buffer.toString();     // converting stringbuffer to string…..

                    runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                       Toast.makeText(AddImage.this, "Result : res", Toast.LENGTH_LONG).show();
                    }
                });
                    //System.out.println("Response => " +  EntityUtils.toString(response.getEntity()));
             }
             return res;
        }

        public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
            int width = image.getWidth();
            int height = image.getHeight();

            float bitmapRatio = (float)width / (float) height;
            if (bitmapRatio > 0) {
                width = maxSize;
                height = (int) (width / bitmapRatio);
            } else {
                height = maxSize;
                width = (int) (height * bitmapRatio);
            }
            return Bitmap.createScaledBitmap(image, width, height, true);
    }



}

main xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/caption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:hint="Insert a caption" />
 <Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/caption"
android:paddingLeft="10dp"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner1"
android:layout_weight="1"
android:text="Post"
android:onClick="onclick" />


<ImageView 
    android:id="@+id/imageView"
       android:layout_width="300dp"
       android:layout_height="300dp"
       android:layout_below="@+id/btn1"
       android:paddingLeft="20dp"/>

</RelativeLayout>

mgridadapter

public class GridImageMainAdapter extends ArrayAdapter<GridImages> {

    private Context mContext;
    private int layoutResourceId;
    private ArrayList<GridImages> mGridImages = new ArrayList<GridImages>();

    public GridImageMainAdapter(Context mContext, int layoutResourceId, ArrayList<GridImages> mGridImages) {
        super(mContext, layoutResourceId, mGridImages);
        this.layoutResourceId = layoutResourceId;
        this.mContext = mContext;
        this.mGridImages = mGridImages;
    }


    /**
     * Updates grid data and refresh grid items.
     * @param mGridData
     */
    public void setGridData(ArrayList<GridImages> mGridImages) {
        this.mGridImages = mGridImages;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder;
        if (BuildConfig.DEBUG) {
            Picasso.with(mContext).setIndicatorsEnabled(true);
            Picasso.with(mContext).setLoggingEnabled(true);
        }
        if (row == null) {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.titleTextView = (TextView) row.findViewById(R.id.grid_item_title);
            holder.imageView = (ImageView) row.findViewById(R.id.grid_item_image);
            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }

        GridImages item = mGridImages.get(position);
        holder.titleTextView.setText(Html.fromHtml(item.Gettitle()));

        Picasso.
        with(mContext).
        load(item.Getimage())
        .placeholder(R.drawable.ic_launcher) // can also be a drawable
         .fit() // will explain later
        .into(holder.imageView);

        return row;
    }

    static class ViewHolder {
        TextView titleTextView;
        ImageView imageView;
    }
}

解决方案

Add mGridAdapter.notifyDatasetChange() after you change the gridview data